errors

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 18, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ErrUnknown = Error("unknown error")

ErrUnknown is an unknown error type

Variables

View Source
var MaskErrs = true

MaskErrs this is a compile time flag to indicate whether to mask errors that can leak private or sensitive information. IMPORTANT!!! DO NOT CHANGE AT RUNTIME in production code.

Functions

func AppendError

func AppendError(err, errn error) error

AppendError returns a new listError if errn == nil, return err if err is of type listError and if errn is of type listerror, append errn errors to err and return err

func GetErrs

func GetErrs(err error) []error

GetErrs gets the list of errors if its a list

func GetHTTPDetails

func GetHTTPDetails(err error) (code int, msg string)

GetHTTPDetails returns a http code and message default http code is 500.

func IsOfType

func IsOfType(terr, err error) bool

IsOfType returns if the err is of type terr

func Len

func Len(err error) int

Len returns the total number of errors if err is listError, return len(listError.errs) if err == nil, return 0 else return 1

func Mask

func Mask(err error) error

Mask returns the mask for the error

func New

func New(format string, args ...interface{}) error

New returns a new error with message passed. if args are passed, we will format the message with args Example: New("some error") returns error with exact string passed New("some error: %v", "some context") returns error with message "some error: some context"

func NewHTTPError

func NewHTTPError(c int, err error) error

NewHTTPError returns an HTTPError.

func NewTypedError

func NewTypedError(terr, err error) error

NewTypedError returns a new error of type typedError

func StackTrace

func StackTrace(err error) string

StackTrace returns the stack trace attached to the error if any

func WithStackTrace

func WithStackTrace(err error) error

WithStackTrace attaches stack trace to error. Note: if the err already holds a stack trace, that trace will be replace with latest

Types

type Error

type Error string

Error is a string that implements error this will have interesting side effects of having constant errors

func (Error) Error

func (e Error) Error() string

Error returns error message

type TypedError

type TypedError interface {
	IsOfType(terr error) bool
	Mask() error
}

TypedError can be implemented by any type error

Jump to

Keyboard shortcuts

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