Documentation
¶
Overview ¶
ErrorUtils facilitates error handling and reporting
The package provides a custom error type that can be used to add additional information to an error message. The recommendation is to use the NewReport function to create a new error report. The lineRef is only used in debug mode. The exitcode is only used for terminating errors. Return simple errors such as user errors with fmt.Errorf and not with NewReport to avoid verbosity. Details type is capable of wrapping and extends urfave/cli functionality to retain information on exit codes.
Index ¶
- Constants
- func Change(l logrus.Level, a logAction)
- func ChangeWriter(l logrus.Level, w io.Writer)
- func ExitOnFail(err error, o ...Option)
- func LogFailures(err error, o ...Option)
- func LogFailuresf(err error, format string, o ...Option)
- func NotifyClose(file io.Closer)
- func PanicOnFail(err error, o ...Option)
- func SafeClose(file io.Closer, origErr *error)
- func WarnOnFail(err error, o ...Option)
- func WarnOnFailf(err error, format string, o ...Option)
- type Details
- type Handler
- type MyFormatter
- type Option
Constants ¶
const ( Redirect logAction = iota Suppress )
Variables ¶
This section is empty.
Functions ¶
func LogFailuresf ¶
Failure has been detected, log it formatted string should contain one '%s' for the error message
func NotifyClose ¶
NotifyClose visibilizes errors on defer for functions that do not return an error
func PanicOnFail ¶
depriecated legacy panic, replace with ExitOnFail or use panic() instead does not support altPrint and can't handle detail nils
func SafeClose ¶
SafeClose closes a file and appends any errors to the error that a function is supposed to return https://wstrm.dev/posts/errors-join-heart-defer/
func WarnOnFail ¶
func WarnOnFailf ¶
formatted string should contain one '%s' for the error message
Types ¶
type Details ¶
type Details struct {
// contains filtered or unexported fields
}
Details is a custom error type that can be used to add additional information to an error message
func HandleFailure ¶
HandleFailure handles an error by logging it and then calling the handler function If the handler function returns an error, it is logged as well
func New ¶
Adds context to an error. Subtle nil check: returns nil if both error and withInner are nil. Bubbles up inner if err is nil. WithMessage does *not* guarantee a new error report (use NewReport); undefined behavior with multiple withInner options.
func NewReport ¶
Succinct syntax for new error report
Recommended for errors that could potentially be bugs, otherwise use fmt.Errorf. LineRef is only used in debug mode
func (*Details) HasAltprint ¶
type MyFormatter ¶ added in v0.2.0
type Option ¶
type Option func(*Details)
func WithExitCode ¶
func WithLineRef ¶
WithLineRef is an option to add a line reference to the error message. use a random string instead of the line number. Calling this option on an existing Details value will append the new lineref to the existing one with a '_' separator.