errors

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: LGPL-2.1 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

Calls the standard As function. As finds the first error in err's tree that matches target, and if one is found, sets target to that error value.

Parameters:

  • err - error to search in,
  • target - target error.

Returns:

  • true if a match is found, false otherwise.

func Is

func Is(err error, target error) bool

Calls the standard Is function. Is reports whether any error in err's tree matches target.

Parameters:

  • err - error to search in,
  • target - target error.

Returns:

  • true if a match is found, false otherwise.

func IsGonatusError

func IsGonatusError(err error) bool

Checks if the given error is a Gonatus error.

Parameters:

  • err - error to check.

Returns:

  • true if the error is a Gonatus error, false otherwise.

func Join

func Join(errs ...error) error

Calls the standard Join function. Creates an error that wraps the given errors.

Parameters:

  • errs - any number of errors to join.

Returns:

  • new error.

func New

func New(conf ErrorConf) error

Creates a new Gonatus error.

Parameters:

  • conf - serialized error.

Returns:

  • created error.

func NewMisappError

func NewMisappError(src gonatus.Gobjecter, msg string) error

Creates a new source wrapper with a missapplication error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewNilError

func NewNilError(src gonatus.Gobjecter, level ErrorLevel, msg string) error

Creates a new source wrapper with a nil error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewNotFoundError

func NewNotFoundError(src gonatus.Gobjecter, level ErrorLevel, msg string) error

Creates a new source wrapper with a not found error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewNotImplError

func NewNotImplError(src gonatus.Gobjecter) error

Creates a new source wrapper with a not implemented error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewSrcWrapper

func NewSrcWrapper(src gonatus.Gobjecter, err error) error

Wraps the given error with a wrapper containing information about the object which caused it. If the error level is below the seriousness threshold, the text of the wrapper will be empty.

Parameters:

  • src - Gobject which called the function,
  • err - error to wrap.

Returns:

  • created error.

func NewStateError

func NewStateError(src gonatus.Gobjecter, level ErrorLevel, msg string) error

Creates a new source wrapper with a state error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewUnknownError

func NewUnknownError(src gonatus.Gobjecter) error

Creates a new source wrapper with an unknown error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func NewValueError

func NewValueError(src gonatus.Gobjecter, level ErrorLevel, msg string) error

Creates a new source wrapper with a value error.

Parameters:

  • src - source of the error.

Returns:

  • created error.

func OfType

func OfType(err error, errType ErrorType) bool

Checks if the given error is of the given error type.

Parameters:

  • err - error to check,
  • errType - type to check.

Returns:

  • true if the error is of the type, false otherwise.

func Serialize

func Serialize(err error) gonatus.Conf

func Traceback

func Traceback(err error) string

Acquires a traceback of the given error. If no traceback was created, message "No traceback." is returned.

Parameters:

  • err - error to trace.

Returns:

  • traceback.

func Unwrap

func Unwrap(err error) error

Acquires a error wrapped inside the given error. If the given error is not a Gonatus error, the standard Unwrap mehod is called.

Parameters:

  • err - error to unwrap.

Returns:

  • wrapped error, nil if there is not one.

func Wrap

func Wrap(msg string, errType ErrorType, wrapped error) error

Creates a new error which wraps the given error. The new error has the wrapper level.

Parameters:

  • msg - wrapper message,
  • errType - type of the wrapper,
  • wrapped - errror to wrap.

Returns:

  • new error.

Types

type ErrorConf

type ErrorConf struct {
	Type      ErrorType   `json:"type"`
	Level     ErrorLevel  `json:"level,omitempty"`
	Msg       string      `json:"msg"`
	Traceback string      `json:"traceback,omitempty"`
	Wrapped   []ErrorConf `json:"wrapped,omitempty"`
}

type ErrorLevel

type ErrorLevel int

Seriousness of the error. The values are synchronized with the Slog library.

const (
	LevelWrapper ErrorLevel = -8 // Not even an error, the actual one is wrapped inside.
	LevelInfo    ErrorLevel = 0  // Non-standard situation has occurred, but program continues normally.
	LevelWarning ErrorLevel = 4  // Something did not work out, alternative approach used.
	LevelError   ErrorLevel = 8  // Normal error level.
	LevelFatal   ErrorLevel = 12 // Most serious error, impossible to continue.
)

type ErrorType

type ErrorType string

Type of the error.

const (
	TypeNA       ErrorType = "UndeterminedError"    // The type of the error was not specified
	TypeUnknown  ErrorType = "UnknownError"         // The program got into a state which should theoretically be impossible.
	TypeNil      ErrorType = "NilError"             // Value missing where expected.
	TypeValue    ErrorType = "ValueError"           // Value present but not valid.
	TypeState    ErrorType = "StateError"           // The program got into an incorrect state.
	TypeNotFound ErrorType = "NotFoundError"        // The required value could not be found.
	TypeMisapp   ErrorType = "MissapplicationError" // The function was incorrectly used by the user.
	TypeNotImpl  ErrorType = "NotImplementedError"  // The function is not implemented by this object.
)

Jump to

Keyboard shortcuts

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