Documentation
¶
Index ¶
- Variables
- func As(err error, target interface{}) bool
- func Cause(err error) error
- func Errorf(code GoCode, format string, args ...interface{}) error
- func Is(err, target error) bool
- func Join(errs ...error) error
- func Unwrap(err error) error
- func WithMessage(err error, message string) error
- func WithMessagef(err error, format string, args ...interface{}) error
- func Wrap(err error, message string) error
- func Wrapf(err error, format string, args ...interface{}) error
- type DBCode
- type DatabaseError
- type Error
- type GoCode
Constants ¶
This section is empty.
Variables ¶
var ( NotImplemented Error = New(CodeNotImplemented, "Not implemented") NoDatabase Error = New(CodeNoDatabase, "No database connection") UnknownDriver Error = New(CodeUnknownDriver, "Unknown driver") NoTableName Error = New(CodeNoTableName, "No table name") NoWhereClause Error = New(CodeNoWhereClause, "No where clause in query") FieldNull Error = New(CodeFieldNull, "Field cannot be null") LastInsertId Error = New(CodeLastInsertId, "Last insert id is not valid") UnsupportedLookup Error = New(CodeUnsupportedLookup, "Unsupported lookup type") AlreadyExecuted Error = New(CodeAlreadyExecuted, "Query has already been executed") CheckFailed Error = New(CodeCheckFailed, "Check failed") InvalidContentType Error = New(CodeContentTypeNotFound, "Content type not found") TypeMismatch Error = New(CodeTypeMismatch, "received type does not match expected type") NilPointer Error = New(CodeNilPointer, "received nil pointer, expected a pointer to initialized value") FieldNotFound Error = New(CodeFieldNotFound, "field not found in model definition") ValueError Error = New(CodeValueError, "error retrieving value") NoUniqueKey Error = New(CodeNoUniqueKey, "could not find unique key for model") SaveFailed Error = New(CodeSaveFailed, "failed to save model") NoChanges Error = New(CodeNoChanges, "No changes were made", sql.ErrNoRows) NoResults Error = New(CodeNoResults, "No results found", sql.ErrNoRows) NoRows Error = New(CodeNoRows, "No rows in result set", sql.ErrNoRows, NoResults) MultipleRows Error = New(CodeMultipleRows, "Multiple rows in result set") UnexpectedRowCount Error = New(CodeUnexpectedRowCount, "Unexpected row count in result set", sql.ErrNoRows) // Common Errors Across All GenericError DatabaseError = dbError(CodeGenericError, "Error") ConnectionFailed DatabaseError = dbError(CodeConnectionFailed, "Failed to connect to database") AuthenticationFailed DatabaseError = dbError(CodeAuthenticationFailed, "Invalid username or password") ProtocolError DatabaseError = dbError(CodeProtocolError, "Database protocol error") Timeout DatabaseError = dbError(CodeTimeout, "Operation timed out") InternalError DatabaseError = dbError(CodeInternalError, "Internal database error") ConnectionClosed DatabaseError = dbError(CodeConnectionClosed, "Connection already closed") ConnectionLost DatabaseError = dbError(CodeConnectionLost, "Lost connection to database server") // DDL/Schema Errors Exists DatabaseError = &databaseError{code: CodeExists} NotExists DatabaseError = &databaseError{code: CodeNotExists} InvalidTable DatabaseError = dbError(CodeInvalidTable, "Invalid or unknown table", NoTableName, TableNotFound) TableExists DatabaseError = dbError(CodeTableExists, "Table already exists", Exists) TableNotFound DatabaseError = dbError(CodeTableNotFound, "Table does not exist", NotExists) InvalidColumn DatabaseError = dbError(CodeInvalidColumn, "Invalid or unknown column", FieldNotFound) ColumnExists DatabaseError = dbError(CodeColumnExists, "Column already exists", Exists) ColumnNotFound DatabaseError = dbError(CodeColumnNotFound, "Column does not exist", NotExists) IndexExists DatabaseError = dbError(CodeIndexExists, "Index already exists", Exists) IndexNotFound DatabaseError = dbError(CodeIndexNotFound, "Index does not exist", NotExists) ConstraintExists DatabaseError = dbError(CodeConstraintExists, "Constraint already exists", Exists) ConstraintNotFound DatabaseError = dbError(CodeConstraintNotFound, "Constraint not found", NotExists) // Data & Type Errors DBTypeMismatch DatabaseError = dbError(CodeDBTypeMismatch, "Type mismatch or invalid cast", TypeMismatch) InvalidEnumValue DatabaseError = dbError(CodeInvalidEnum, "Invalid enum value") StringTooLong DatabaseError = dbError(CodeStringTooLong, "String value is too long") InvalidDefaultValue DatabaseError = dbError(CodeInvalidDefault, "Invalid default value") DateOutOfRange DatabaseError = dbError(CodeDateOutOfRange, "Date/time value out of range") EncodingError DatabaseError = dbError(CodeEncodingError, "Invalid character encoding") PrecisionLoss DatabaseError = dbError(CodePrecisionLoss, "Value lost precision during conversion") DivisionByZero DatabaseError = dbError(CodeDivisionByZero, "Division by zero") // Constraint errors ConstraintViolation DatabaseError = dbError(CodeConstraintViolation, "Constraint violation") ForeignKeyViolation DatabaseError = dbError(CodeForeignKeyViolation, "Foreign key constraint failed", ConstraintViolation) UniqueViolation DatabaseError = dbError(CodeUniqueViolation, "Unique constraint failed", ConstraintViolation) NullViolation DatabaseError = dbError(CodeNotNullViolation, "NULL value in non-null column", FieldNull) CheckViolation DatabaseError = dbError(CodeCheckConstraintViolation, "Check constraint failed", ConstraintViolation) // Transaction Errors TransactionStarted DatabaseError = dbError(CodeTransactionStarted, "Transaction already started") TransactionDeadlock DatabaseError = dbError(CodeTransactionDeadlock, "Transaction deadlock detected") FailedStartTransaction DatabaseError = dbError(CodeFailedStartTransaction, "Failed to start transaction") NoTransaction DatabaseError = dbError(CodeNoTransaction, "Transaction was not started") TransactionNil DatabaseError = dbError(CodeTransactionNil, "Transaction is nil", NoTransaction) RollbackFailed DatabaseError = dbError(CodeRollbackFailed, "Failed to rollback transaction", sql.ErrTxDone) CommitFailed DatabaseError = dbError(CodeCommitFailed, "Failed to commit transaction", sql.ErrTxDone) SavepointFailed DatabaseError = dbError(CodeSavepointFailed, "Failed to create savepoint in transaction") CrossDatabaseTransaction DatabaseError = dbError(CodeCrossDatabaseTransaction, "Cross-database transaction is not allowed") // Query / QueryRow / Exec SyntaxError DatabaseError = dbError(CodeSyntaxError, "Syntax error in SQL statement") DeadlockDetected DatabaseError = dbError(CodeDeadlockDetected, "Deadlock detected") QueryCanceled DatabaseError = dbError(CodeQueryCanceled, "Query was canceled") QueryTimeout DatabaseError = dbError(CodeQueryTimeout, "Query execution timed out") TooManyConnections DatabaseError = dbError(CodeTooManyConnections, "Too many connections", IOError) OutOfMemory DatabaseError = dbError(CodeOutOfMemory, "Database out of memory", IOError) IOError DatabaseError = dbError(CodeIOError, "I/O error occurred during operation") DiskFull DatabaseError = dbError(CodeDiskFull, "Disk full or write failure", IOError) PermissionDenied DatabaseError = dbError(CodePermissionDenied, "Permission denied for operation") SerializationFailure DatabaseError = dbError(CodeSerializationFailure, "Could not serialize access due to concurrent update") // Planning / Execution AmbiguousColumn DatabaseError = dbError(CodeAmbiguousColumn, "Ambiguous column reference") UnsupportedFeature DatabaseError = dbError(CodeUnsupportedFeature, "Feature not supported by this database") FunctionNotImplemented DatabaseError = dbError(CodeFunctionNotImplemented, "Function not implemented by this database") InvalidCast DatabaseError = dbError(CodeInvalidCast, "Invalid type cast", DBTypeMismatch) // System/Internal CorruptedData DatabaseError = dbError(CodeCorruptedData, "Database file/data corrupted") InconsistentState DatabaseError = dbError(CodeInconsistentState, "Internal database state is inconsistent") AssertionFailure DatabaseError = dbError(CodeAssertionFailure, "Internal assertion failed") )
Functions ¶
func As ¶
As finds the first error in err's chain that matches target, and if so, sets target to that error value and returns true.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error matches target if the error's concrete value is assignable to the value pointed to by target, or if the error has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
As will panic if target is not a non-nil pointer to either a type that implements error, or to any interface type. As returns false if err is nil.
func Cause ¶
Cause returns the underlying cause of the error, if possible. An error value has a cause if it implements the following interface:
type causer interface {
Cause() error
}
If the error does not implement Cause, the original error will be returned. If the error is nil, nil will be returned without further investigation.
func Errorf ¶
Errorf formats according to a format specifier and returns the string as a value that satisfies error.
func Is ¶
Is reports whether any error in err's chain matches target.
The chain consists of err itself followed by the sequence of errors obtained by repeatedly calling Unwrap.
An error is considered to match a target if it is equal to that target or if it implements a method Is(error) bool such that Is(target) returns true.
func Unwrap ¶
Unwrap returns the result of calling the Unwrap method on err, if err's type contains an Unwrap method returning error. Otherwise, Unwrap returns nil.
func WithMessage ¶
WithMessage annotates err with a new message. If err is nil, WithMessage returns nil.
func WithMessagef ¶
WithMessagef annotates err with the format specifier. If err is nil, WithMessagef returns nil.
Types ¶
type DBCode ¶
type DBCode string
const ( CodeInvalid DBCode = "E000" // Common Errors Across All CodeGenericError DBCode = "E001" CodeConnectionFailed DBCode = "E002" CodeAuthenticationFailed DBCode = "E003" CodeProtocolError DBCode = "E004" CodeTimeout DBCode = "E005" CodeInternalError DBCode = "E006" CodeConnectionClosed DBCode = "E007" CodeConnectionLost DBCode = "E008" // DDL/Schema Errors CodeExists DBCode = "E109" CodeNotExists DBCode = "E110" CodeInvalidTable DBCode = "E111" CodeTableExists DBCode = "E112" CodeTableNotFound DBCode = "E113" CodeInvalidColumn DBCode = "E114" CodeColumnExists DBCode = "E115" CodeColumnNotFound DBCode = "E116" CodeIndexExists DBCode = "E117" CodeIndexNotFound DBCode = "E118" CodeConstraintExists DBCode = "E119" CodeConstraintNotFound DBCode = "E120" // Data & Type Errors CodeDBTypeMismatch DBCode = "E201" CodeInvalidEnum DBCode = "E202" CodeStringTooLong DBCode = "E203" CodeInvalidDefault DBCode = "E204" CodeDateOutOfRange DBCode = "E205" CodeEncodingError DBCode = "E206" CodePrecisionLoss DBCode = "E207" CodeDivisionByZero DBCode = "E208" // Constraint errors CodeConstraintViolation DBCode = "E301" CodeForeignKeyViolation DBCode = "E302" CodeUniqueViolation DBCode = "E303" CodeNotNullViolation DBCode = "E304" CodeCheckConstraintViolation DBCode = "E305" // Transaction Errors CodeTransactionStarted DBCode = "E401" CodeTransactionDeadlock DBCode = "E402" CodeFailedStartTransaction DBCode = "E403" CodeNoTransaction DBCode = "E404" CodeTransactionNil DBCode = "E405" CodeRollbackFailed DBCode = "E406" CodeCommitFailed DBCode = "E407" CodeSavepointFailed DBCode = "E408" CodeCrossDatabaseTransaction DBCode = "E409" // Query / QueryRow / Exec CodeSyntaxError DBCode = "E501" CodeDeadlockDetected DBCode = "E502" CodeQueryCanceled DBCode = "E503" CodeQueryTimeout DBCode = "E504" CodeTooManyConnections DBCode = "E505" CodeOutOfMemory DBCode = "E506" CodeIOError DBCode = "E507" CodeDiskFull DBCode = "E508" CodePermissionDenied DBCode = "E509" CodeSerializationFailure DBCode = "E510" // Planning / Execution CodeAmbiguousColumn DBCode = "E601" CodeUnsupportedFeature DBCode = "E602" CodeFunctionNotImplemented DBCode = "E603" CodeInvalidCast DBCode = "E604" // System/Internal CodeCorruptedData DBCode = "E701" CodeInconsistentState DBCode = "E702" CodeAssertionFailure DBCode = "E703" )
type DatabaseError ¶
type DatabaseError interface {
Error() string
Code() DBCode
Reason() error
WithCause(otherErr error) DatabaseError
Wrap(message string) DatabaseError
Wrapf(format string, args ...any) DatabaseError
}
func InvalidDatabaseError ¶
func InvalidDatabaseError(err error) DatabaseError
func UnknownDatabaseError ¶
func UnknownDatabaseError(code DBCode, message string, related ...error) DatabaseError
type GoCode ¶
type GoCode string
const ( CodeUnknown GoCode = "Unknown" CodeNotImplemented GoCode = "NotImplemented" CodeNoDatabase GoCode = "NoDatabase" CodeUnknownDriver GoCode = "UnknownDriver" CodeNoTableName GoCode = "NoTableName" CodeNoWhereClause GoCode = "NoWhereClause" CodeContentTypeNotFound GoCode = "ContentTypeNotFound" CodeLastInsertId GoCode = "LastInsertId" CodeFieldNull GoCode = "FieldNull" CodeNilPointer GoCode = "NilPointer" CodeFieldNotFound GoCode = "FieldNotFound" CodeTypeMismatch GoCode = "TypeMismatch" CodeValueError GoCode = "ValueError" CodeUnsupportedLookup GoCode = "UnsupportedLookup" CodeAlreadyExecuted GoCode = "AlreadyExecuted" CodeNoUniqueKey GoCode = "NoUniqueKey" CodeSaveFailed GoCode = "SaveFailed" CodeCheckFailed GoCode = "CheckFailed" CodeNoChanges GoCode = "NoChanges" CodeNoResults GoCode = "NoResults" CodeNoRows GoCode = "NoRows" CodeMultipleRows GoCode = "MultipleRows" CodeUnexpectedRowCount GoCode = "UnexpectedRowCount" )