HandleError handles the error according to the contextutil. See the comment of `HandleErrorWithAlias` for detailed logic. It also allows using `errors.ErrorGroup`, in this case, it'll handle each error in order, and return the first error it founds.
(err error)
| 103 | // It also allows using `errors.ErrorGroup`, in this case, it'll handle each error in order, and return the first error |
| 104 | // it founds. |
| 105 | func (ctx *Context) HandleError(err error) error { |
| 106 | if err == nil { |
| 107 | return nil |
| 108 | } |
| 109 | // The function of handling `errors.ErrorGroup` is placed in `HandleError` but not in `HandleErrorWithAlias`, because |
| 110 | // it's hard to give a proper error and warn alias for an error group. |
| 111 | if errs, ok := err.(errors.ErrorGroup); ok { |
| 112 | for _, singleErr := range errs.Errors() { |
| 113 | singleErr = ctx.HandleError(singleErr) |
| 114 | // If the one error is found, just return it. |
| 115 | // TODO: consider whether it's more appropriate to continue to handle other errors. For example, other errors |
| 116 | // may need to append warnings. The current behavior is same with TiDB original behavior before using |
| 117 | // `errctx` to handle multiple errors. |
| 118 | if singleErr != nil { |
| 119 | return singleErr |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return nil |
| 124 | } |
| 125 | |
| 126 | return ctx.HandleErrorWithAlias(err, err, err) |
| 127 | } |
| 128 | |
| 129 | // HandleErrorWithAlias handles the error according to the contextutil. |
| 130 | // 1. If the `internalErr` is not `"pingcap/errors".Error`, or the error code is not defined in the `errGroupMap`, or the error |