MCPcopy
hub / github.com/purpleidea/mgmt / WithoutContext

Function WithoutContext

util/errwrap/errwrap.go:81–111  ·  view source on GitHub ↗

WithoutContext passes through an error if it's nil or is a normal error. If it is a multierror, then it removes all errors of context cancellation unless that's all there is. If there's one error remaining, it returns that. Otherwise it returns a new multierror with what's left.

(err error)

Source from the content-addressed store, hash-verified

79// that's all there is. If there's one error remaining, it returns that.
80// Otherwise it returns a new multierror with what's left.
81func WithoutContext(err error) error {
82 if err == nil {
83 return nil
84 }
85
86 multiErr, ok := err.(*multierror.Error)
87 if !ok {
88 return err
89 }
90
91 if len(multiErr.Errors) == 0 {
92 return err // unexpected
93 }
94
95 errs := []error{}
96 for _, e := range multiErr.Errors {
97 if e == context.Canceled {
98 continue // remove
99 }
100 errs = append(errs, e)
101 }
102
103 if len(errs) == 0 {
104 return context.Canceled
105 }
106 //if len(errs) == 1 {
107 // return errs[0]
108 //}
109
110 return Join(errs)
111}
112
113// NoContextCanceled return nil if the error is a context.Canceled. Otherwise it
114// returns the error.

Callers 15

TestAstFunc2Function · 0.92
TestAstFunc3Function · 0.92
RunMethod · 0.92
RunMethod · 0.92
TestWithoutContext1Function · 0.85
TestWithoutContext2Function · 0.85
TestWithoutContext3Function · 0.85
TestWithoutContext4Function · 0.85
TestWithoutContext5Function · 0.85
TestWithoutContext6Function · 0.85
TestWithoutContext7Function · 0.85

Calls 1

JoinFunction · 0.70

Tested by 15

TestAstFunc2Function · 0.74
TestAstFunc3Function · 0.74
TestWithoutContext1Function · 0.68
TestWithoutContext2Function · 0.68
TestWithoutContext3Function · 0.68
TestWithoutContext4Function · 0.68
TestWithoutContext5Function · 0.68
TestWithoutContext6Function · 0.68
TestWithoutContext7Function · 0.68
TestWithoutContext8Function · 0.68
TestWithoutContext9Function · 0.68