-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotator.go
More file actions
43 lines (36 loc) · 741 Bytes
/
annotator.go
File metadata and controls
43 lines (36 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package errors
type AnnotatorFunc func(*Error)
func WithMessage(message string) AnnotatorFunc {
return func(err *Error) {
if message == "" {
return
}
if err.message == "" {
err.message = message
} else {
err.message = message + ": " + err.message
}
}
}
type Attribute struct {
key string
value any
}
func Attr(key string, value any) Attribute {
return Attribute{key: key, value: value}
}
func WithAttrs(attrs ...Attribute) AnnotatorFunc {
return func(err *Error) {
if err.attrs == nil {
err.attrs = make(map[string]any, len(attrs))
}
for _, attr := range attrs {
err.attrs[attr.key] = attr.value
}
}
}
func WithNoStackTrace() AnnotatorFunc {
return func(err *Error) {
err.stack = nil
}
}