terror

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClassAutoid     = RegisterErrorClass(1, "autoid")
	ClassDDL        = RegisterErrorClass(2, "ddl")
	ClassDomain     = RegisterErrorClass(3, "domain")
	ClassEvaluator  = RegisterErrorClass(4, "evaluator")
	ClassExecutor   = RegisterErrorClass(5, "executor")
	ClassExpression = RegisterErrorClass(6, "expression")
	ClassAdmin      = RegisterErrorClass(7, "admin")
	ClassKV         = RegisterErrorClass(8, "kv")
	ClassMeta       = RegisterErrorClass(9, "meta")
	ClassOptimizer  = RegisterErrorClass(10, "planner")
	ClassParser     = RegisterErrorClass(11, "parser")
	ClassPerfSchema = RegisterErrorClass(12, "perfschema")
	ClassPrivilege  = RegisterErrorClass(13, "privilege")
	ClassSchema     = RegisterErrorClass(14, "schema")
	ClassServer     = RegisterErrorClass(15, "server")
	ClassStructure  = RegisterErrorClass(16, "structure")
	ClassVariable   = RegisterErrorClass(17, "variable")
	ClassXEval      = RegisterErrorClass(18, "xeval")
	ClassTable      = RegisterErrorClass(19, "table")
	ClassTypes      = RegisterErrorClass(20, "types")
	ClassGlobal     = RegisterErrorClass(21, "global")
	ClassMockTikv   = RegisterErrorClass(22, "mocktikv")
	ClassJSON       = RegisterErrorClass(23, "json")
	ClassTiKV       = RegisterErrorClass(24, "tikv")
	ClassSession    = RegisterErrorClass(25, "session")
	ClassPlugin     = RegisterErrorClass(26, "plugin")
	ClassUtil       = RegisterErrorClass(27, "util")
)

Error classes.

View Source
var (
	// ErrClassToMySQLCodes is the map of ErrClass to code-set.
	ErrClassToMySQLCodes = make(map[ErrClass]map[ErrCode]struct{})
	// ErrCritical is the critical error class.
	ErrCritical = ClassGlobal.NewStdErr(CodeExecResultIsEmpty, mysql.Message("critical error %v", nil))
	// ErrResultUndetermined is the error when execution result is unknown.
	ErrResultUndetermined = ClassGlobal.NewStdErr(
		CodeResultUndetermined,
		mysql.Message("execution result undetermined", nil),
	)
)

Functions

func Call

func Call(fn func() error)

Call executes a function and checks the returned err.

func ErrorEqual

func ErrorEqual(err1, err2 error) bool

ErrorEqual returns a boolean indicating whether err1 is equal to err2.

func ErrorNotEqual

func ErrorNotEqual(err1, err2 error) bool

ErrorNotEqual returns a boolean indicating whether err1 isn't equal to err2.

func Log

func Log(err error)

Log logs the error if it is not nil.

func MustNil

func MustNil(err error, closeFuns ...func())

MustNil cleans up and fatals if err is not nil.

func RegisterFinish

func RegisterFinish()

RegisterFinish makes the register of new error panic. The use pattern should be register all the errors during initialization, and then call RegisterFinish.

func ToSQLError

func ToSQLError(e *Error) *mysql.SQLError

ToSQLError convert Error to mysql.SQLError.

Types

type ErrClass

type ErrClass int

ErrClass represents a class of errors.

func GetErrClass

func GetErrClass(e *Error) ErrClass

GetErrClass returns the error class of the error.

func RegisterErrorClass

func RegisterErrorClass(classCode int, desc string) ErrClass

RegisterErrorClass registers new error class for terror.

func (ErrClass) EqualClass

func (ec ErrClass) EqualClass(err error) bool

EqualClass returns true if err is *Error with the same class.

func (ErrClass) New deprecated

func (ec ErrClass) New(code ErrCode, message string) *Error

New defines an *Error with an error code and an error message. Usually used to create base *Error. Attention: this method is not goroutine-safe and usually be used in global variable initializer

Deprecated: use NewStd or NewStdErr instead.

func (ErrClass) NewStd

func (ec ErrClass) NewStd(code ErrCode) *Error

NewStd calls New using the standard message for the error code Attention: this method is not goroutine-safe and usually be used in global variable initializer

func (ErrClass) NewStdErr

func (ec ErrClass) NewStdErr(code ErrCode, message *mysql.ErrMessage) *Error

NewStdErr defines an *Error with an error code, an error message and workaround to create standard error.

func (ErrClass) NotEqualClass

func (ec ErrClass) NotEqualClass(err error) bool

NotEqualClass returns true if err is not *Error with the same class.

func (ErrClass) String

func (ec ErrClass) String() string

String implements fmt.Stringer interface.

func (ErrClass) Synthesize

func (ec ErrClass) Synthesize(code ErrCode, message string) *Error

Synthesize synthesizes an *Error in the air it didn't register error into ErrClassToMySQLCodes so it's goroutine-safe and often be used to create Error came from other systems like TiKV.

type ErrCode

type ErrCode int

ErrCode represents a specific error type in a error class. Same error code can be used in different error classes.

const (

	// CodeUnknown is for errors of unknown reason.
	CodeUnknown ErrCode = -1
	// CodeExecResultIsEmpty indicates execution result is empty.
	CodeExecResultIsEmpty ErrCode = 3

	// CodeMissConnectionID indicates connection id is missing.
	CodeMissConnectionID ErrCode = 1

	// CodeResultUndetermined indicates the sql execution result is undetermined.
	CodeResultUndetermined ErrCode = 2
)

type ErrCodeText

type ErrCodeText string

ErrCodeText is a textual error code that represents a specific error type in an error class.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is the prototype of a class of errors. Use Normalize or ErrClass.New / ErrClass.NewStd to create one.

func Normalize

func Normalize(message string, opts ...NormalizeOption) *Error

Normalize creates a new Error prototype.

func (*Error) Code

func (e *Error) Code() ErrCode

func (*Error) Equal

func (e *Error) Equal(other error) bool

Equal reports whether other is or wraps an Error with the same ID as e.

func (*Error) Error

func (e *Error) Error() string

func (*Error) FastGen

func (e *Error) FastGen(format string, args ...any) error

FastGen returns a copy of e with a new message format and arguments.

func (*Error) FastGenByArgs

func (e *Error) FastGenByArgs(args ...any) error

FastGenByArgs returns a copy of e with new arguments.

func (*Error) GenWithStack

func (e *Error) GenWithStack(format string, args ...any) error

GenWithStack returns a copy of e with a new message format and arguments.

func (*Error) GenWithStackByArgs

func (e *Error) GenWithStackByArgs(args ...any) error

GenWithStackByArgs returns a copy of e with new arguments.

func (*Error) GetMsg

func (e *Error) GetMsg() string

func (*Error) ID

func (e *Error) ID() ErrorID

ID returns the unique identifier of this error.

func (*Error) Is

func (e *Error) Is(other error) bool

Is reports whether other is an Error with the same ID. Allows usage with errors.Is from the standard library.

func (*Error) NotEqual

func (e *Error) NotEqual(other error) bool

NotEqual is the inverse of Equal.

func (*Error) RFCCode

func (e *Error) RFCCode() RFCErrorCode

type ErrorID

type ErrorID string

ErrorID is a textual identifier of an Error prototype.

type NormalizeOption

type NormalizeOption func(*Error)

NormalizeOption configures an Error created via Normalize.

func MySQLErrorCode

func MySQLErrorCode(code int) NormalizeOption

MySQLErrorCode sets the numeric MySQL error code of the Error.

func RFCCodeText

func RFCCodeText(s string) NormalizeOption

RFCCodeText sets the textual RFC code of the Error.

type RFCErrorCode

type RFCErrorCode string

RFCErrorCode is the textual error code in the form {Class}:{Code}.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL