exit

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 3 Imported by: 7

Documentation

Overview

Package exit defines exit and error behavior of programs and commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// Exit code of the program (if applicable)
	ExitCode
	// Message for this error
	// Messages should pass docfmt.Validate
	Message string
}

Error represents any error state by a program. It implements the builtin error interface.

The zero value represents that no error occured and is ready to use.

func AsError

func AsError(err error) Error

AsError asserts that err is either nil or of type Error and returns it. When err is nil, the zero value of type Error is returned.

If err is not nil and not of type Error, calls panic().

func (Error) Error

func (err Error) Error() string

Error returns the error message belonging to this error.

func (Error) WithMessage

func (err Error) WithMessage(message string) Error

WithMessage returns a copy of this error with the same Code but different Message.

The new message is the message passed as an argument.

func (Error) WithMessageF

func (err Error) WithMessageF(args ...interface{}) Error

WithMessageF returns a copy of this error with the same Code but different Message. The new message is the current message, formatted using a call to SPrintf and the arguments.

type ExitCode

type ExitCode uint8

ExitCode determines the exit behavior of a program. These are returned as an exit code to the operating system. See ExitCode.Return().

const (
	// ExitZero indicates that no error occured.
	// It is the zero value of type ExitCode.
	ExitZero ExitCode = 0

	// ExitGeneric indicates a generic error occured within this invocation.
	// This typically implies a subcommand-specific behavior wants to return failure to the caller.
	ExitGeneric ExitCode = 1

	// ExitUnknownCommand indicates that the user attempted to call a subcommand that is not defined.
	ExitUnknownCommand ExitCode = 2

	// ExitGeneralArguments indiciates that the user attempted to pass invalid general arguments to the program.
	ExitGeneralArguments ExitCode = 3
	// ExitCommandArguments indicates that the user attempted to pass invalid command-specific arguments to a subcommand.
	ExitCommandArguments ExitCode = 4

	// ExitPanic indicates that the go code called panic() inside the executation of the current program.
	// This typically implies a bug inside a program.
	ExitPanic ExitCode = 255
)

func (ExitCode) Return

func (code ExitCode) Return()

Return returns this ExitCode to the operating system by invoking os.Exit().

Jump to

Keyboard shortcuts

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