fail

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 6 Imported by: 3

README

Fail

a Custom Error with ExitCode and Message that add a StackTrace automatically. There are also some helper functions.

Support

If you find this project useful, you can support its development by buying me a coffee:

Buy Me A Coffee

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsCustomError

func AsCustomError(err error) (CustomError, CustomError)

AsCustomError casts the given error to an CustomError

func Equals

func Equals(a, b error) bool

Equals checks if the given errors are equal

func FormatJsonError

func FormatJsonError(err error) string

FormatJsonError returns a JSON formatted string representation of the given error

func HasErrors

func HasErrors(errs ...error) bool

HasErrors checks if the given errors contain any errors

func HasWarnings

func HasWarnings(errs ...error) bool

HasWarnings checks if the given errors contain any warnings

func IsCustomError

func IsCustomError(err error) bool

IsCustomError checks if the given error is an CustomError

func IsError

func IsError(err error) bool

IsError checks if the given error is an Error

func IsWarning

func IsWarning(err error) bool

IsWarning checks if the given error is an Warning

Types

type CustomError

type CustomError interface {
	error
	GetExitCode() int
	GetMessage() string
	GetStack() string
	AsWarning() CustomError
	AsError() CustomError
	WithIcon(icon string) CustomError
}

CustomError is a custom error type that can be an Error or a Warning based on the ExitCode

func Combine

func Combine(errs ...error) CustomError

Combine combines multiple CustomError into one CustomError

func Wrap

func Wrap(err error, additional ...string) CustomError

Wrap wraps the given error with additional information

type Error

type Error struct {
	ExitCode int
	Message  string
	Stack    string
	Icon     string
}

Error is a custom error type that can be an Error or a Warning based on the ExitCode

func (*Error) AsError

func (e *Error) AsError() CustomError

AsError changes the exit code of the Error to -1

func (*Error) AsWarning

func (e *Error) AsWarning() CustomError

AsWarning changes the exit code of the Error to -2

func (*Error) Error

func (e *Error) Error() string

Error returns a string representation of the Error

func (*Error) GetExitCode

func (e *Error) GetExitCode() int

GetExitCode returns the exit code of the Error

func (*Error) GetMessage

func (e *Error) GetMessage() string

GetMessage returns the message of the Error

func (*Error) GetStack

func (e *Error) GetStack() string

GetStack returns the stacktrace of the Error

func (*Error) String

func (e *Error) String() string

func (*Error) WithIcon

func (e *Error) WithIcon(icon string) CustomError

type ErrorList

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

ErrorList is a list of errors

func GetErrors

func GetErrors(errs ...error) ErrorList

GetErrors returns a list of Errors from the given errors

func GetWarnings

func GetWarnings(errs ...error) ErrorList

GetWarnings returns a list of warnings from the given errors

func NewErrorList

func NewErrorList(errors ...error) *ErrorList

func (*ErrorList) Count

func (e *ErrorList) Count() int

Count gets the number of Elements in the List

func (*ErrorList) Error

func (e *ErrorList) Error() string

Error returns a string representation of the error list

func (*ErrorList) String

func (e *ErrorList) String() string

func (*ErrorList) ToErrorList

func (e *ErrorList) ToErrorList() []error

ToErrorList returns the underlying error list

type JsonErrorResponse

type JsonErrorResponse struct {
	ExitCode int    `json:"exitCode"`
	Message  string `json:"message"`
}

Jump to

Keyboard shortcuts

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