Documentation ¶
Overview ¶
Package errors contains helper functions for returning errors from a CLI.
Index ¶
- func Errorf(message string, args ...interface{}) error
- func IsError(actual error, expected error) bool
- func PrintErrorWithStackTrace(err error) string
- func Recover(onPanic func(cause error))
- func Unwrap(err error) error
- func WithPanicHandling(action func(c *cli.Context) error) func(c *cli.Context) error
- func WithStackTrace(err error) error
- func WithStackTraceAndPrefix(err error, message string, args ...interface{}) error
- type ErrorWithExitCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Errorf ¶ added in v0.17.1
Errorf creates a new error and wraps in an Error type that contains the stack trace.
func IsError ¶
Returns true if actual is the same type of error as expected. This method unwraps the given error objects (if they are wrapped in objects with a stacktrace) and then does a simple equality check on them.
func PrintErrorWithStackTrace ¶
Convert the given error to a string, including the stack trace if available
func Recover ¶
func Recover(onPanic func(cause error))
A method that tries to recover from panics, and if it succeeds, calls the given onPanic function with an error that explains the cause of the panic. This function should only be called from a defer statement.
func Unwrap ¶
If the given error is a wrapper that contains a stacktrace, unwrap it and return the original, underlying error. In all other cases, return the error unchanged
func WithPanicHandling ¶
Use this to wrap every command you add to *cli.App to handle panics by logging them with a stack trace and returning an error up the chain.
func WithStackTrace ¶
Wrap the given error in an Error type that contains the stack trace. If the given error already has a stack trace, it is used directly. If the given error is nil, return nil.
func WithStackTraceAndPrefix ¶
Wrap the given error in an Error type that contains the stack trace and has the given message prepended as part of the error message. If the given error already has a stack trace, it is used directly. If the given error is nil, return nil.
Types ¶
type ErrorWithExitCode ¶
If this error is returned, the program should exit with the given exit code.
func (ErrorWithExitCode) Error ¶
func (err ErrorWithExitCode) Error() string