MCPcopy
hub / github.com/dropbox/godropbox / FindWrappedError

Function FindWrappedError

errors/errors.go:278–298  ·  view source on GitHub ↗

Performs a deep check of wrapped errors to find one which is selected by the given classifier func. The classifer is called on all non-nil errors found, starting with topErr, then on each inner wrapped error in turn until it returns non-nil which ends the scan. If the classifier ever returns a non-

(
	topErr error,
	classifier func(curErr, topErr error) error,
)

Source from the content-addressed store, hash-verified

276// with `true` to indicate something was found. Otherwise this function will return
277// `topErr, false`.
278func FindWrappedError(
279 topErr error,
280 classifier func(curErr, topErr error) error,
281) (error, bool) {
282 for curErr := topErr; curErr != nil; {
283 classifiedErr := classifier(curErr, topErr)
284 if classifiedErr != nil {
285 return classifiedErr, true
286 }
287
288 dbxErr, ok := curErr.(DropboxError)
289 if !ok || dbxErr == nil {
290 break
291 }
292 curErr = dbxErr.Unwrap()
293 if curErr == nil {
294 break
295 }
296 }
297 return topErr, false
298}

Callers 4

TestFindWrappedErrorNilsFunction · 0.85

Calls 1

UnwrapMethod · 0.65

Tested by 4

TestFindWrappedErrorNilsFunction · 0.68