Documentation ¶
Index ¶
- Variables
- type Context
- func (ctx *Context) AppendNote(err error)
- func (ctx *Context) AppendWarning(err error)
- func (ctx *Context) HandleError(err error) error
- func (ctx *Context) HandleErrorWithAlias(internalErr error, err error, warnErr error) error
- func (ctx *Context) LevelForGroup(errGroup ErrGroup) Level
- func (ctx *Context) LevelMap() LevelMap
- func (ctx *Context) WithErrGroupLevel(eg ErrGroup, l Level) Context
- func (ctx *Context) WithErrGroupLevels(levels LevelMap) Context
- func (ctx *Context) WithStrictErrGroupLevel() Context
- type ErrGroup
- type Level
- type LevelMap
Constants ¶
This section is empty.
Variables ¶
var StrictNoWarningContext = NewContext(contextutil.IgnoreWarn)
StrictNoWarningContext returns all errors directly, and ignore all errors
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context defines how to handle an error
func NewContext ¶
func NewContext(handler contextutil.WarnAppender) Context
NewContext creates an error context to handle the errors and warnings
func NewContextWithLevels ¶
func NewContextWithLevels(levels LevelMap, handler contextutil.WarnAppender) Context
NewContextWithLevels creates an error context to handle the errors and warnings
func (*Context) AppendNote ¶
AppendNote appends the error to warning with level 'Note'. If the inner `warnHandler` is nil, do nothing.
func (*Context) AppendWarning ¶
AppendWarning appends the error to warning. If the inner `warnHandler` is nil, do nothing.
func (*Context) HandleError ¶
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.
func (*Context) HandleErrorWithAlias ¶
HandleErrorWithAlias handles the error according to the contextutil.
- If the `internalErr` is not `"pingcap/errors".Error`, or the error code is not defined in the `errGroupMap`, or the error level is set to `LevelError`(0), the `err` will be returned directly.
- If the error level is set to `LevelWarn`, the `warnErr` will be appended as a warning.
- If the error level is set to `LevelIgnore`, this function will return a `nil`.
In most cases, these three should be the same. If there are many different kinds of error internally, but they are expected to give the same error to users, the `err` can be different form `internalErr`. Also, if the warning is expected to be different from the initial error, you can also use the `warnErr` argument.
TODO: is it good to give an error code for internal only errors? Or should we use another way to distinguish different group of errors? TODO: both `types.Context` and `errctx.Context` can handle truncate error now. Refractor them.
func (*Context) LevelForGroup ¶
LevelForGroup returns the level for a specified group.
func (*Context) WithErrGroupLevel ¶
WithErrGroupLevel sets a `Level` for an `ErrGroup`
func (*Context) WithErrGroupLevels ¶
WithErrGroupLevels sets `levelMap` for an `ErrGroup`
func (*Context) WithStrictErrGroupLevel ¶
WithStrictErrGroupLevel makes the context to return the error directly for any kinds of errors.
type ErrGroup ¶
type ErrGroup int
ErrGroup groups the error according to the behavior of handling errors
const ( // ErrGroupTruncate is the group of truncated errors ErrGroupTruncate ErrGroup = iota // ErrGroupDupKey is the group of duplicate key errors ErrGroupDupKey // ErrGroupBadNull is the group of bad null errors ErrGroupBadNull // ErrGroupNoDefault is the group of no default value errors ErrGroupNoDefault // ErrGroupDividedByZero is the group of divided by zero errors ErrGroupDividedByZero // ErrGroupAutoIncReadFailed is the group of auto increment read failed errors ErrGroupAutoIncReadFailed // ErrGroupNoMatchedPartition is the group of no partition is matched errors. ErrGroupNoMatchedPartition )
type Level ¶
type Level uint8
Level defines the behavior for each error
func ResolveErrLevel ¶
ResolveErrLevel resolves the error level according to the `ignore` and `warn` flags if ignore is true, it will return `LevelIgnore` to ignore the error, otherwise, it will return `LevelWarn` or `LevelError` according to the `warn` flag Only one of `ignore` and `warn` can be true.