Debian Codegraph @

errors.go

raw
1 package raven
2
3 type causer interface {
4 Cause() error
5 }
6
7 type errWrappedWithExtra struct {
8 err error
9 extraInfo map[string]interface{}
10 }
11
12 func (ewx *errWrappedWithExtra) Error() string {
13 return ewx.err.Error()
14 }
15
16 func (ewx *errWrappedWithExtra) Cause() error {
17 return ewx.err
18 }
19
20 func (ewx *errWrappedWithExtra) ExtraInfo() Extra {
21 return ewx.extraInfo
22 }
23
24 // Adds extra data to an error before reporting to Sentry
25 func WrapWithExtra(err error, extraInfo map[string]interface{}) error {
26 return &errWrappedWithExtra{
27 err: err,
28 extraInfo: extraInfo,
29 }
30 }
31
32 type ErrWithExtra interface {
33 Error() string
34 Cause() error
35 ExtraInfo() Extra
36 }
37
38 // Iteratively fetches all the Extra data added to an error,
39 // and it's underlying errors. Extra data defined first is
40 // respected, and is not overridden when extracting.
41 func extractExtra(err error) Extra {
42 extra := Extra{}
43
44 currentErr := err
45 for currentErr != nil {
46 if errWithExtra, ok := currentErr.(ErrWithExtra); ok {
47 for k, v := range errWithExtra.ExtraInfo() {
48 extra[k] = v
49 }
50 }
51
52 if errWithCause, ok := currentErr.(causer); ok {
53 currentErr = errWithCause.Cause()
54 } else {
55 currentErr = nil
56 }
57 }
58
59 return extra
60 }