errors

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 4 Imported by: 13

README

errors

Build Status Go Report Card Coverage Status GoDoc

extension of errors for the following features:

  • annotation error
  • error with code, support grpc error code
  • error with stack use pkg/errors

Quick Start


import "github.com/x-mod/errors"

//annotation error
e1 := errors.Annotate(err, "annotations")
e11 := errors.Annotatef(err, "annotations %s", "format")

//code error
e2 := errors.WithCode(err, YourCode)
//get error's code value
v2 := errors.ValueFrom(e2)

e3 := errors.WithStack(err)
//print stack info
fmt.Printf("%+v", e3)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotate

func Annotate(err error, annotation string) error

Annotate an error with annotation

func Annotatef

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

Annotatef an error with annotation

func As added in v0.2.0

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

As standard func

func CodeError

func CodeError(code Code) error

CodeError a new error from code

func Errorf

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

Errorf standard func

func Is added in v0.2.0

func Is(err, target error) bool

Is standard func

func New

func New(err string) error

New errorstring error

func Unwrap added in v0.2.0

func Unwrap(err error) error

Unwrap standard func

func ValueFrom

func ValueFrom(err error) int32

ValueFrom get code from the error support code value from grpc status

func WithCode

func WithCode(err error, code Code) error

WithCode wrap err with code

Types

type Code

type Code interface {
	Value() int32
	String() string
}

Code interface

type ErrNo added in v0.2.1

type ErrNo int32

func (ErrNo) Error added in v0.2.1

func (e ErrNo) Error() string

func (ErrNo) GRPCStatus added in v0.2.2

func (e ErrNo) GRPCStatus() *status.Status

GRPCStatus make ErrNo support grpc status

func (ErrNo) String added in v0.2.1

func (e ErrNo) String() string

func (ErrNo) Value added in v0.2.1

func (e ErrNo) Value() int32

Jump to

Keyboard shortcuts

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