errors

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package errors provides error types and codes for XxSql database.

Index

Constants

View Source
const (
	// Connection errors (1xxx)
	ErrConnectionFailed   = 1001
	ErrConnectionTimeout  = 1002
	ErrConnectionRefused  = 1003
	ErrConnectionReset    = 1004
	ErrTooManyConnections = 1005
	ErrConnectionClosed   = 1006
	ErrAuthFailed         = 1007
	ErrAuthTimeout        = 1008
	ErrPermissionDenied   = 1009

	// Protocol errors (2xxx)
	ErrProtocolViolation = 2001
	ErrInvalidMessage    = 2002
	ErrMessageTooLarge   = 2003
	ErrInvalidEncoding   = 2004
	ErrHandshakeFailed   = 2005

	// SQL parsing errors (3xxx)
	ErrSyntaxError        = 3001
	ErrInvalidToken       = 3002
	ErrUnexpectedToken    = 3003
	ErrUnterminatedString = 3004
	ErrUnterminatedIdent  = 3005
	ErrInvalidNumber      = 3006
	ErrInvalidIdentifier  = 3007
	ErrReservedWord       = 3008

	// Semantic errors (4xxx)
	ErrUndefinedTable      = 4001
	ErrUndefinedColumn     = 4002
	ErrUndefinedFunction   = 4003
	ErrAmbiguousColumn     = 4004
	ErrDuplicateTable      = 4005
	ErrDuplicateColumn     = 4006
	ErrDuplicateIndex      = 4007
	ErrTypeMismatch        = 4008
	ErrInvalidCast         = 4009
	ErrDivisionByZero      = 4010
	ErrNullViolation       = 4011
	ErrUniqueViolation     = 4012
	ErrForeignKeyViolation = 4013
	ErrCheckViolation      = 4014
	ErrInvalidConstraint   = 4015
	ErrTableExists         = 4016
	ErrIndexExists         = 4017
	ErrDatabaseExists      = 4018
	ErrDatabaseNotFound    = 4019

	// Execution errors (5xxx)
	ErrQueryFailed             = 5001
	ErrInsertFailed            = 5002
	ErrUpdateFailed            = 5003
	ErrDeleteFailed            = 5004
	ErrTransactionFailed       = 5005
	ErrDeadlockDetected        = 5006
	ErrLockTimeout             = 5007
	ErrRollbackFailed          = 5008
	ErrSavepointFailed         = 5009
	ErrPreparedStatementFailed = 5010
	ErrInvalidCursor           = 5011
	ErrBufferOverflow          = 5012
	ErrMemoryLimitExceeded     = 5013

	// Internal errors (6xxx)
	ErrInternalError      = 6001
	ErrStorageError       = 6002
	ErrIndexError         = 6003
	ErrCacheError         = 6004
	ErrWALError           = 6005
	ErrCheckpointError    = 6006
	ErrRecoveryError      = 6007
	ErrCorruptionDetected = 6008
	ErrBackupError        = 6009
	ErrConfigError        = 6010
	ErrLogFileError       = 6011
)

Error codes organized by category (1xxx-6xxx ranges)

View Source
const (
	SQLStateConnectionException          = "08000"
	SQLStateConnectionDoesNotExist       = "08003"
	SQLStateConnectionFailure            = "08006"
	SQLStateSyntaxError                  = "42000"
	SQLStateInvalidTableDefinition       = "42P01"
	SQLStateInvalidColumnDefinition      = "42701"
	SQLStateDuplicateObject              = "42710"
	SQLStateUndefinedObject              = "42704"
	SQLStateAmbiguousColumn              = "42702"
	SQLStateIntegrityConstraintViolation = "23000"
	SQLStateUniqueViolation              = "23505"
	SQLStateForeignKeyViolation          = "23503"
	SQLStateCheckViolation               = "23514"
	SQLStateNullViolation                = "23502"
	SQLStateDivisionByZero               = "22012"
	SQLStateInternalError                = "XX000"
	SQLStateDataCorruption               = "XX001"
	SQLStateDiskFull                     = "53100"
	SQLStateOutOfMemory                  = "53000"
)

SQL state codes (SQL standard)

Variables

This section is empty.

Functions

This section is empty.

Types

type Position

type Position struct {
	Line   int // 1-based line number
	Column int // 1-based column number
}

Position represents a position in SQL text for error reporting.

type XxSqlError

type XxSqlError struct {
	Code     int            // Primary error code (1xxx-6xxx ranges)
	SubCode  int            // Secondary code for detail
	SQLState string         // SQL standard state code (5 chars)
	Message  string         // User-facing message
	Detail   string         // Technical details
	Hint     string         // Suggested fix
	Position *Position      // Line/column in SQL
	Context  map[string]any // Additional context
}

XxSqlError represents a structured error with comprehensive information.

func ErrColumnNotFound

func ErrColumnNotFound(colName, tableName string) *XxSqlError

ErrColumnNotFound creates a column not found error.

func ErrConfig

func ErrConfig(msg string) *XxSqlError

ErrConfig creates a configuration error.

func ErrConnection

func ErrConnection(msg string) *XxSqlError

ErrConnection creates a connection error.

func ErrDeadlock

func ErrDeadlock() *XxSqlError

ErrDeadlock creates a deadlock error.

func ErrInternal

func ErrInternal(msg string) *XxSqlError

ErrInternal creates an internal error.

func ErrStorage

func ErrStorage(msg string) *XxSqlError

ErrStorage creates a storage error.

func ErrSyntax

func ErrSyntax(msg string, line, col int) *XxSqlError

ErrSyntax creates a syntax error.

func ErrTableAlreadyExists

func ErrTableAlreadyExists(tableName string) *XxSqlError

ErrTableAlreadyExists creates a duplicate table error.

func ErrTableNotFound

func ErrTableNotFound(tableName string) *XxSqlError

ErrTableNotFound creates a table not found error.

func NewError

func NewError(code int, message string) *XxSqlError

NewError creates a new XxSqlError with the given code and message.

func (*XxSqlError) CodeRange

func (e *XxSqlError) CodeRange() string

CodeRange returns the category of the error based on its code.

func (*XxSqlError) Error

func (e *XxSqlError) Error() string

Error implements the error interface.

func (*XxSqlError) Is

func (e *XxSqlError) Is(target error) bool

Is checks if the error matches the target code.

func (*XxSqlError) Unwrap

func (e *XxSqlError) Unwrap() error

Unwrap returns nil (no wrapped error).

func (*XxSqlError) WithContext

func (e *XxSqlError) WithContext(key string, value any) *XxSqlError

WithContext adds context key-value pairs to the error.

func (*XxSqlError) WithDetail

func (e *XxSqlError) WithDetail(detail string) *XxSqlError

WithDetail sets the detail for the error.

func (*XxSqlError) WithHint

func (e *XxSqlError) WithHint(hint string) *XxSqlError

WithHint sets the hint for the error.

func (*XxSqlError) WithPosition

func (e *XxSqlError) WithPosition(line, column int) *XxSqlError

WithPosition sets the position for the error.

func (*XxSqlError) WithSQLState

func (e *XxSqlError) WithSQLState(state string) *XxSqlError

WithSQLState sets the SQL state for the error.

func (*XxSqlError) WithSubCode

func (e *XxSqlError) WithSubCode(subCode int) *XxSqlError

WithSubCode sets the subcode for the error.

Jump to

Keyboard shortcuts

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