Documentation ¶
Overview ¶
Example ¶
err := getHandler() // Note: You can also use "%+v" to show the full stack trace about error fmt.Printf("%v\n", err)
Output: alice@example.com: getHandler: >> businessLogic: counter value = 3: >> getFromDB: kind database error: >> sql: no rows in result set
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func E ¶
func E(args ...interface{}) error
E builds an error value from its arguments. There must be at least one argument or E panics. The type of each argument determines its meaning. If more than one argument of a given type is presented, only the last one is recorded.
The types are:
Op The operation of the function who make a call to other function that returns an error. E.g. taskUsecase.GetAll. UserEmail The email of the user attempting the operation. string Treated as an error message. errors.Kind The class of error, such as internal server error, record not found, ...etc. error The underlying error that triggered this one.
If the error is printed, only those items that have been set to non-zero values will appear in the result.
If Kind is not specified or Other, we set it to the Kind of the underlying error.
Types ¶
type Error ¶
type Error struct { // Op is the operation being performed, usually the name of the method // being invoked (userUsecase.Get, tokenRepo.Insert, ...etc.). Op Op // UserEmail is the email of the user attempting the operation. UserEmail UserEmail // Kind is the class of error, such as Record not found, // or "Other" if its class is unknown or irrelevant. Kind Kind // Msg is some additional information you want to add. Msg Msg // The underlying error that triggered this one, if any. Err error }
Error is the type that implements the error interface. It contains a number of fields, each of different type. An Error value may leave some values unset.
func (*Error) Format ¶
Format provide Format method to satisfy fmt.Formatter interface, it is used by function like fmt.Printf with verb like: '%+v' to display stack trace of a pkg/error Error type.
func (*Error) StackTrace ¶
func (e *Error) StackTrace() errors.StackTrace
StackTrace() allow us to print the stacktrace message by calling e.Err 's StackTrace() method, if e.Err is nil or e.Err is not a stacktracer, we just return nil.
type Kind ¶
type Kind uint8
Kind defines the kind of error this is.
const ( KindOther Kind = iota // Unclassified error. This value is not printed in the error message. KindRecordNotFound // Record not found when we request some resource in database. KindDuplicateEmail // Duplicate Email error. KindEditConflict // Edit conflict while manipulating database. KindInvalidCredentials // Edit conflict while manipulating database. KindFailedValidation // Failed validation error. KindInternal // Internal server error. KindDatabase // Error happened while querying database, this should be treated as subset of internal error and logged it carefully. )
Kinds of errors.
The values of the error kinds are common between both clients and servers.
type Msg ¶
type Msg string