MCPcopy Create free account
hub / github.com/chain/Core / WithData

Function WithData

errors/errors.go:146–159  ·  view source on GitHub ↗

WithData returns a new error that wraps err as a chain error message containing a value of type map[string]interface{} as an extra data item. The map contains the values in the map in err, if any, plus the items in keyval. Keyval takes the form k1, v1, k2, v2, ... Values kN must be strings. Calling

(err error, keyval ...interface{})

Source from the content-addressed store, hash-verified

144// Note that if err already has a data item of any other type,
145// it will not be accessible via the returned error value.
146func WithData(err error, keyval ...interface{}) error {
147 if err == nil {
148 return nil
149 }
150 // TODO(kr): add vet check for odd-length keyval and non-string keys
151 newkv := make(map[string]interface{})
152 for k, v := range Data(err) {
153 newkv[k] = v
154 }
155 for i := 0; i < len(keyval); i += 2 {
156 newkv[keyval[i].(string)] = keyval[i+1]
157 }
158 return withData(err, newkv)
159}
160
161// Data returns the data item in err, if any.
162func Data(err error) map[string]interface{} {

Callers 1

TestDataFunction · 0.85

Calls 2

withDataFunction · 0.85
DataFunction · 0.70

Tested by 1

TestDataFunction · 0.68