Categorygithub.com/klahssen/errors
modulepackage
0.2.2
Repository: https://github.com/klahssen/errors.git
Documentation: pkg.go.dev

# README

errors

import "github.com/klahssen/errors"

Overview

Imported Packages

Index

Package files

errors.go strings.go

func FirstError

func FirstError(t ErrType, op string, causes ...error) error

FirstError create a neew error with the first non nil error

func GetGRPCCode

func GetGRPCCode(err error) codes.Code

GetGRPCCode tries to cast error as *Err and return a gRPC code based on internal ErrType

func Is

func Is(t ErrType, err error) bool

Is checks if err is of error type t

func New

func New(t ErrType, op string, cause error) error

New constructs a new error

func SameErrorMessage

func SameErrorMessage(want, got error) bool

type Err

type Err struct {
    Typ   ErrType // error type
    Op    string  // operation that failed
    Cause error   // cause
}

Err holds an error

func (*Err) Error

func (e *Err) Error() string

Error to implement error interface. Tries to write : <error_type>: cause

func (*Err) Origin

func (e *Err) Origin() error

Origin returns the deepest error unwrapped from inner Cause error recursively

type ErrType

type ErrType uint8

ErrType is the error type

const (
    TypeOther      ErrType = iota // default
    TypeInternal                  // internal error
    TypeInvalidArg                // invalid arguments for an operation
    TypeInvalidRequestBody
    TypeInvalidOp     // invalid operation (method not allowed for exampled)
    TypeNotFound      // resource not found
    TypeAlreadyExists // conflict with existing resource
    TypePermission    // not authorized or unauthenticated
    TypeIO            // external io error (network failure etc)
    TypeTimeout
    TypeTooMany         // overload
    TypeUnexpected      // should be escalated
    TypeUnauthenticated // unauthenticated
)

error types

func GetErrType

func GetErrType(err error) ErrType

GetErrType returns the ErrType. Returns TypeOther if not castable as Err

func (ErrType) String

func (t ErrType) String() string

String returns the printable version of the error type

type String

type String string

String is a string that implements the error and stringer interfaces

func (String) Error

func (s String) Error() string

func (String) String

func (s String) String() string

Generated by godoc2ghmd

# Functions

FirstError create a neew error with the first non nil error.
GetErrType returns the ErrType.
GetGRPCCode tries to cast error as *Err and return a gRPC code based on internal ErrType.
HTTPStatusFromCode returns the equivalent http status from a grpc code.
Is checks if err is of error type t.
New constructs a new error.
No description provided by the author

# Constants

conflict with existing resource.
internal error.
invalid arguments for an operation.
invalid operation (method not allowed for exampled).
error types.
external io error (network failure etc).
resource not found.
default.
not authorized or unauthenticated.
error types.
overload.
unauthenticated.
should be escalated.

# Structs

Err holds an error.

# Type aliases

ErrType is the error type.
String is a string that implements the error and stringer interfaces.