WrapError wraps an error with additional context that allows the part of the serialized type that caused the problem to be identified. Underlying errors can be retrieved using Cause() The input error is not modified - a new error should be returned. ErrShortBytes is not wrapped with any context du
(err error, ctx ...any)
| 78 | // ErrShortBytes is not wrapped with any context due to backward compatibility |
| 79 | // issues with the public API. |
| 80 | func WrapError(err error, ctx ...any) error { |
| 81 | switch e := err.(type) { |
| 82 | case errShort: |
| 83 | return e |
| 84 | case contextError: |
| 85 | return e.withContext(ctxString(ctx)) |
| 86 | default: |
| 87 | return errWrapped{cause: err, ctx: ctxString(ctx)} |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | func addCtx(ctx, add string) string { |
| 92 | if ctx != "" { |
searching dependent graphs…