unwrapErrorChain traverses the error chain using errors.Unwrap and returns all error types and messages from the outermost wrapper to the root cause.
(err error)
| 63 | // unwrapErrorChain traverses the error chain using errors.Unwrap and returns |
| 64 | // all error types and messages from the outermost wrapper to the root cause. |
| 65 | func unwrapErrorChain(err error) []errorChainItem { |
| 66 | var chain []errorChainItem |
| 67 | |
| 68 | for err != nil { |
| 69 | var url string |
| 70 | |
| 71 | //nolint:errorlint |
| 72 | if e, ok := err.(errctx.Error); ok { |
| 73 | url = e.DocsURL() |
| 74 | } |
| 75 | |
| 76 | chain = append(chain, errorChainItem{ |
| 77 | Type: errorTypeReplacer.Replace(errctx.ErrorType(err)), |
| 78 | Message: err.Error(), |
| 79 | StackTrace: buildStackTrace(err), |
| 80 | DocsURL: url, |
| 81 | }) |
| 82 | |
| 83 | err = errors.Unwrap(err) |
| 84 | } |
| 85 | |
| 86 | return chain |
| 87 | } |
| 88 | |
| 89 | // buildStackTrace gets the stack trace from the outermost error and marks |
| 90 | // which frames correspond to which errors in the chain. |
no test coverage detected