Documentation
¶
Overview ¶
Package errors provides error types and codes for XxSql database.
Index ¶
- Constants
- type Position
- type XxSqlError
- func ErrColumnNotFound(colName, tableName string) *XxSqlError
- func ErrConfig(msg string) *XxSqlError
- func ErrConnection(msg string) *XxSqlError
- func ErrDeadlock() *XxSqlError
- func ErrInternal(msg string) *XxSqlError
- func ErrStorage(msg string) *XxSqlError
- func ErrSyntax(msg string, line, col int) *XxSqlError
- func ErrTableAlreadyExists(tableName string) *XxSqlError
- func ErrTableNotFound(tableName string) *XxSqlError
- func NewError(code int, message string) *XxSqlError
- func (e *XxSqlError) CodeRange() string
- func (e *XxSqlError) Error() string
- func (e *XxSqlError) Is(target error) bool
- func (e *XxSqlError) Unwrap() error
- func (e *XxSqlError) WithContext(key string, value any) *XxSqlError
- func (e *XxSqlError) WithDetail(detail string) *XxSqlError
- func (e *XxSqlError) WithHint(hint string) *XxSqlError
- func (e *XxSqlError) WithPosition(line, column int) *XxSqlError
- func (e *XxSqlError) WithSQLState(state string) *XxSqlError
- func (e *XxSqlError) WithSubCode(subCode int) *XxSqlError
Constants ¶
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 ErrPIDFileError = 6012 )
Error codes organized by category (1xxx-6xxx ranges)
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 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 ErrConnection ¶
func ErrConnection(msg string) *XxSqlError
ErrConnection creates a connection 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.