NewWithDepthf is like Newf() except the depth to capture the stack trace is configurable. See the doc of `New()` for more details.
(depth int, format string, args ...interface{})
| 64 | // trace is configurable. |
| 65 | // See the doc of `New()` for more details. |
| 66 | func NewWithDepthf(depth int, format string, args ...interface{}) error { |
| 67 | // If there's the verb %w in here, shortcut to fmt.Errorf() |
| 68 | // and store the safe details as extra payload. That's |
| 69 | // because we don't want to re-implement the error wrapping |
| 70 | // logic from 'fmt' in there. |
| 71 | var err error |
| 72 | var errRefs []error |
| 73 | for _, a := range args { |
| 74 | if e, ok := a.(error); ok { |
| 75 | errRefs = append(errRefs, e) |
| 76 | } |
| 77 | } |
| 78 | redactable, wrappedErr := redact.HelperForErrorf(format, args...) |
| 79 | if wrappedErr != nil { |
| 80 | err = &withNewMessage{cause: wrappedErr, message: redactable} |
| 81 | } else { |
| 82 | err = &leafError{redactable} |
| 83 | } |
| 84 | for _, e := range errRefs { |
| 85 | err = secondary.WithSecondaryError(err, e) |
| 86 | } |
| 87 | err = withstack.WithStackDepth(err, 1+depth) |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | // Wrap wraps an error with a message prefix. |
| 92 | // A stack trace is retained. |
no test coverage detected
searching dependent graphs…