modulepackage
1.1.1
Repository: https://github.com/nofeaturesonlybugs/errors.git
Documentation: pkg.go.dev
# README
golang package for enhanced errors that capture file and line number information, the call stack, relevant identifiers, and a handle back to the original error for type switching.
Replacement for fmt.Errorf(...):
err := errors.Errorf("Failed to do something; here's a value %v",len(data))
fmt.Printf("%#v\n",err) // Prints full stack trace.
Wrap another function's error:
_, err := net.Dial( "tcp", "localhost:8080" )
if err != nil {
return errors.Go( err )
}
Obtain the original error in order to type switch:
func connect() error {
_, err := net.Dial( "tcp", "localhost:0" )
if err != nil {
return errors.Go( err )
}
return nil
}
err := connect()
switch errors.Original( err ).(type) {
case *net.OpError:
// We know the original type!
}
See the godoc link for more information.
# Functions
AlreadyStarted returns an error representing a service that has already started and can not start again.
Errorf is similar to fmt.Errorf except it returns the enhanced Error interface from this package.
Go returns an Error if the passed `err` is non-nil; the purpose of this function is to wrap contextual information, such as call stack, to the initial error.
Is reports whether any error in err's chain matches target.
NilArgument creates an error when a function argument is nil.
NilMember creates an error when a struct member is nil.
NilReceiver creates an error when a receiver is nil.
Original returns a non-nil interface if the incoming type is an Error from this package.
Stack returns the call stack frames of the caller.
# Interfaces
Error is the interface returned by functions in this package.