-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
39 lines (34 loc) · 941 Bytes
/
error.go
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
package nu
type LabeledError struct {
Msg string `msgpack:"msg"`
Labels []ErrorLabel `msgpack:"labels,omitempty"`
Code string `msgpack:"code,omitempty"`
Url string `msgpack:"url,omitempty"`
Help string `msgpack:"help,omitempty"`
Inner []LabeledError `msgpack:"inner,omitempty"`
}
/*
ErrorLabel is "label" type for [LabeledError].
*/
type ErrorLabel struct {
Text string `msgpack:"text"`
Span Span `msgpack:"span"`
}
/*
AsLabeledError "converts" error to LabeledError - if the
error is already LabeledError it will be "unwrapped",
otherwise new LabeledError will be created wrapping the err.
*/
func AsLabeledError(err error) *LabeledError {
if le, ok := err.(*LabeledError); ok {
return le
}
return &LabeledError{Msg: err.Error()}
}
/*
Error implements Go "error" interface.
The "Msg" is returned as error message.
*/
func (le *LabeledError) Error() string {
return le.Msg
}