MCPcopy
hub / github.com/pingcap/tidb / HandleError

Method HandleError

pkg/errctx/context.go:105–127  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
105func (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

Callers 15

TestContextFunction · 0.95
buildMethod · 0.45
buildHandleMethod · 0.45
GetColumnRowCountFunction · 0.45
columnBetweenRowCountFunction · 0.45
ColumnEqualRowCountFunction · 0.45
HandleBadNullMethod · 0.45

Calls 2

HandleErrorWithAliasMethod · 0.95
ErrorsMethod · 0.65

Tested by 3

TestContextFunction · 0.76
buildMethod · 0.36
TestDecimalFunction · 0.36