errors

package
v0.162.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWriter io.Writer = os.Stderr

ErrWriter is used to write errors to the user. This can be anything implementing the io.Writer interface and defaults to os.Stderr.

View Source
var OsExiter = os.Exit

OsExiter is the function used when the app exits. If not set defaults to os.Exit.

Functions

func HandleExitCoder

func HandleExitCoder(err error)

HandleExitCoder checks if the error fulfills the ExitCoder interface, and if so prints the error to stderr (if it is non-empty) and calls OsExiter with the given exit code. If the given error is a MultiError, then this func is called on all members of the Errors slice and calls OsExiter with the last exit code.

Types

type ErrorFormatter

type ErrorFormatter interface {
	Format(s fmt.State, verb rune)
}

type ExitCoder

type ExitCoder interface {
	error
	ExitCode() int
}

ExitCoder is the interface checked by `App` and `Command` for a custom exit code

type ExitError

type ExitError struct {
	// contains filtered or unexported fields
}

ExitError fulfills both the builtin `error` interface and `ExitCoder`

func NewExitError

func NewExitError(message any, exitCode int) *ExitError

NewExitError makes a new *ExitError

func (*ExitError) Error

func (ee *ExitError) Error() string

Error returns the string message, fulfilling the interface required by `error`

func (*ExitError) ExitCode

func (ee *ExitError) ExitCode() int

ExitCode returns the exit code, fulfilling the interface required by `ExitCoder`

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL