xerrors

package
v0.0.0-...-e31961d Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

README

XErrors

XErrors package wrap Go 1.13 errors package

This package has upspin style error.

Creating Error

Creating error in xerrors is as simple as in errors package

xerrors.New("this is an error)

Error With Kind

Error can be ambigous and hard to categorized, kind is a constant that means to categorized error.

For example:

  • Not Found
  • Internal Error
  • OK
  • Bad Request

To create an error with kind:

xerrors.New("this is an error", xerrors.KindOK)

Error With Op/Operation

Sometimes function need to be tagged, especially for tracing. With op we can tag our error to trace our error more easily.

To create an error with op:

xerrors.New(xerrors.Op("doing_something), "this is an error")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target interface{}) bool

As wrap the error as

func Is

func Is(err, target error) bool

Is wrap the errors is

func New

func New(v ...interface{}) error

New errors

func SetCaller

func SetCaller(c bool)

SetCaller to print the stack-trace of the error

func Unwrap

func Unwrap(err error) error

Unwrap error

Types

type Errors

type Errors struct {
	Err      error
	InnerErr error
	// contains filtered or unexported fields
}

Errors of xerrors

func XUnwrap

func XUnwrap(err error) *Errors

XUnwrap return errors with xerror package type

func (*Errors) Error

func (e *Errors) Error() string

Error return string of error

func (*Errors) Kind

func (e *Errors) Kind() Kind

Kind of errors

func (*Errors) Unwrap

func (e *Errors) Unwrap() error

Unwrap errors

type Fields

type Fields map[string]interface{}

Fields of errors

type Kind

type Kind int16

Kind of errors

const (
	KindOK Kind = iota
	KindNotFound
	KindBadRequest
	KindUnauthorized
	KindInternalError
)

kind of errors

type Op

type Op string

Op is the operation when error happens

func (Op) String

func (op Op) String() string

String value of Op

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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