Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func E ¶
func E(args ...interface{}) error
E for creating new error. error should always be the first param.
func Errorf ¶
Errorf is equivalent to fmt.Errorf, but allows clients to import only this package for all error handling.
func Is ¶
Is reports whether err is an *Error of the given Code. If err is nil then Is returns false.
func Match ¶
Match compares its two error arguments. It can be used to check for expected errors in tests. Both arguments must have underlying type *Error or Match will return false. Otherwise it returns true if every non-zero element of the first error is equal to the corresponding element of the second. If the Err field is a *Error, Match recurs on that field; otherwise it compares the strings returned by the Error methods. Elements that are in the second argument but not present in the first are ignored.
Types ¶
type Code ¶
type Code string
Code defines the kind of error this is, mostly for use by systems that must act differently depending on the error.
const ( CodeUnknown Code = "" // Unclassified or unknown error. CodePermission Code = "permission" // Permission denied. CodeInternal Code = "internal" // Internal error or inconsistency. CodeConflict Code = "conflict" // Action cannot be performed. CodeInvalid Code = "invalid" // Validation failed. CodeNotFound Code = "not_found" // Entity does not exist. CodeGateway Code = "gateway" // Gateway or third party service return error. CodeConfig Code = "config" // Wrong configuration. CodeCircuitBreaker Code = "circuit_breaker" // Circuit breaker error. CodeMarshal Code = "marshal" // JSON marshal error. CodeUnmarshal Code = "unmarshal" // JSON unmarshal error. CodeConversion Code = "conversion" // Conversion error, e.g. string to time conversion. CodeEncryption Code = "encryption" // Encryption error. CodeDecryption Code = "decryption" // Decryption error. CodeDB Code = "db" // Database operation error. CodeDBScan Code = "db_scan" // Database scan error. CodeDBExec Code = "db_exec" // Database exec error. CodeDBQuery Code = "db_query" // Database query error. CodeDBBegin Code = "db_begin" // Database begin transaction error. CodeDBCommit Code = "db_commit" // Database commit error. CodeDBRollback Code = "db_rollback" // Database rollback error. )
Application error codes.
type Error ¶
type Error struct { // Underlying error. Err error // Codes used for Errs to identify known errors in the application. // If the error is expected by Errs object, the errors will be shown as listed in Codes. Code Code // Fields is a fields context similar to logrus.Fields. // Can be used for adding more context to the errors. Fields Fields // OpTraces is a trace of operations. OpTraces []Op // Message is a human-readable message. Message Message // Line describes current error original line. // Only injected when the underlying error is from standard error. Line Line // MetricStatus defines the kind of error should be tracked or not. MetricStatus MetricStatus }
Error defines a standard application error.
type MetricStatus ¶
type MetricStatus string
MetricStatus defines the kind of error should be tracked or not. Useful for alerting system.
const ( MetricStatusSuccess MetricStatus = "success" MetricStatusErr MetricStatus = "error" MetricStatusExpectedErr MetricStatus = "expected_error" )