errors

package
v1.18.9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Error struct and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any(err error, targets ...error) bool

Any reports whether an error in error's chain matches to any error provided in list.

func ExitErr

func ExitErr(text string, err error, code int)

ExitErr prints error to os.Stderr and call os.Exit with given code.

func ExitMsg

func ExitMsg(text string, code int)

ExitMsg prints message to os.Stderr and call os.Exit with given code.

func Is

func Is(err, target error) bool

Is checks if error is equal to target error.

  • err: error to check
  • target: target error to compare

Types

type ErrWrapper

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

ErrWrapper implements error wrapper interface.

func New

func New(code, text string) *ErrWrapper

New returns constructed error wrapper interface.

func Wrap

func Wrap(code, text string, err error) *ErrWrapper

Wrap wraps given error into a new error with format.

func (*ErrWrapper) Error

func (e *ErrWrapper) Error() string

Error implements error interface.

func (*ErrWrapper) Unwrap

func (e *ErrWrapper) Unwrap() error

Unwrap implements error unwrap interface.

func (*ErrWrapper) Wrap

func (e *ErrWrapper) Wrap(err error) *ErrWrapper

Wrap implements error wrapper interface.

type Error

type Error struct {
	Code string `json:"code,omitempty"`
	Msg  string `json:"msg"`
}

Error type for a new application error.

func NewError added in v1.3.5

func NewError(code string, msg string) *Error

NewError create a new error instance given a code and a message.

  • code: error code
  • msg: error message

func NewErrorf added in v1.3.5

func NewErrorf(code string, format string, args ...interface{}) *Error

NewErrorf - create a new error with format

func (*Error) Error added in v1.3.5

func (err *Error) Error() string

Jump to

Keyboard shortcuts

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