mysqlerrors

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2023 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ClientUnknown           = 2000
	ClientBadUnixSocket     = 2002
	ClientBadTCPSocket      = 2005
	ClientWrongProtocol     = 2007
	ClientNetPacketTooLarge = 2020
)

MySQL Client errors as found in the MySQL manual under https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html. Names have been altered so that they make more sense. For example, CR_CONNECTION_ERROR became ClientBadUnixSocket.

Variables

View Source
var (
	ErrContextDeadlineExceeded = errors.New("context deadline exceeded")
)

Functions

func NewFromServerMessage

func NewFromServerMessage(msg interfaces.ServerMessager) error

NewFromServerMessage takes msg and transforms it into an Error.

func NewFromWarning

func NewFromWarning(msg *mysqlxnotice.Warning) error

NewFromWarning takes msg and transforms it into a MySQLWarning.

Types

type Error

type Error struct {
	Inner        error
	Message      string
	Code         int
	SQLState     string
	Severity     int
	Parameters   []any
	ExtraMessage string
}

Error holds information of MySQL returned error and is implementing the Go error interface.

func New

func New(code int, params ...any) *Error

New instantiates an Error object with code being the MySQL client or server error code. When the message contains placeholders (is a format specifier), params are used to interpolate them. When one of the params is an error, it is used as a wrapped error. Panics when params contains more than one value which is error-type.

func (*Error) Error

func (e *Error) Error() string

Error is the string representation of the error. Messages look the same, but they are differently formatted than the MySQL Client message to conform Go best practices.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type MySQLWarning

type MySQLWarning struct {
	Message string
	Code    int
	Level   string
}

MySQLWarning holds information of MySQL returned warning and is implementing the Go error interface.

func (*MySQLWarning) Error

func (w *MySQLWarning) Error() string

Error is the string representation of the warning, mimicking how MySQL would show them.

Jump to

Keyboard shortcuts

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