errors

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddExtrasToError

func AddExtrasToError(err error, _extras map[string]interface{}) error

AddExtrasToError checks if the input error implements a causer interface. If it does, it checks if the Cause is of internal type *rung. When this check also passes, it adds the input _extras to the existing extras information. In case the checks fail, the original error is returned.

func AddTagsToError

func AddTagsToError(err error, _tags map[string]string) error

AddTagsToError checks if the input error implements a causer interface. If it does, it checks if the Cause is of internal type *rung. When this check also passes, it adds the input _tags to the existing tags information. In case the checks fail, the original error is returned.

func Code

func Code(err error, defaultCode int) (code int)

This allows us to attach a response code with an error. This is achieved by implementing the errorCode interface:

type errorCode interface {
       Code() bool
}

If the error does not implement errorCode, 500 will be returned. If the error is nil, 200 will be returned without further investigation. The logic will loop through the topmost error of the stack followed by all it's causes provided it implements the causer interface:

  type causer interface {
		  Cause() error
  }

If any one of the causes implements errorCode and returns a non-zero Code(), that code is returned to the calling function.

func DeepestCause

func DeepestCause(err error) error

Finds the deepest non-nil cause

func Extras

func Extras(err error) (cumulativeExtras map[string]interface{})

func Fatal

func Fatal(err error) (isFatal bool)

Fatal is a condition to see if an error can be ignored or not. An error value has an Fatal condition if it implements the following interface:

type fatality interface {
       Fatal() bool
}

If the error does not implement Fatal, false will be returned. If the error is nil, false will be returned without further investigation. The logic will loop through the topmost error of the stack followed by all it's causes provided it implements the causer interface:

  type causer interface {
		  Cause() error
  }

If any one of the causes is fatal, the error is deemed fatal. i.e. irrecoverable

func Ignore

func Ignore(err error) bool

func NewError

func NewError(_msg string, _cause error, _fatal bool) error

Creates an error which is chained with a cause

func NewErrorToIgnore

func NewErrorToIgnore(_msg string, _cause error) error

NewErrorToIgnore returns an error that informs loggers to ignore it

func NewErrorWithCode

func NewErrorWithCode(_msg string, code int, _cause error) error

NewErrorWithCode returns an error that has an int code associated with it

func NewErrorWithExtras

func NewErrorWithExtras(_msg string, _cause error, _fatal bool, _extras map[string]interface{}) error

Creates an error which is chained with a cause

func NewErrorWithTags

func NewErrorWithTags(_msg string, _cause error, _fatal bool, _tags map[string]string) error

Creates an error which is chained with a cause

func NewErrorWithTagsAndExtras

func NewErrorWithTagsAndExtras(_msg string, _cause error, _fatal bool, _tags map[string]string, _extras map[string]interface{}) error

func PrintStackTrace

func PrintStackTrace(err error)

Printing the stacktrace of an error. It will print the entire stacktrace starting from the original root cause

func Stacktrace

func Stacktrace(err error) string

Determines the stacktrace of an error. It will retrieve the entire stacktrace starting from the original root cause

func Tags

func Tags(err error) (cumulativeTags map[string]string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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