exerr

package
v0.0.184 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MDTString      metaDataType = "String"
	MDTStringPtr   metaDataType = "StringPtr"
	MDTInt         metaDataType = "Int"
	MDTInt8        metaDataType = "Int8"
	MDTInt16       metaDataType = "Int16"
	MDTInt32       metaDataType = "Int32"
	MDTInt64       metaDataType = "Int64"
	MDTFloat32     metaDataType = "Float32"
	MDTFloat64     metaDataType = "Float64"
	MDTBool        metaDataType = "Bool"
	MDTBytes       metaDataType = "Bytes"
	MDTObjectID    metaDataType = "ObjectID"
	MDTTime        metaDataType = "Time"
	MDTDuration    metaDataType = "Duration"
	MDTStringArray metaDataType = "StringArr"
	MDTIntArray    metaDataType = "IntArr"
	MDTInt32Array  metaDataType = "Int32Arr"
	MDTID          metaDataType = "ID"
	MDTAny         metaDataType = "Interface"
	MDTNil         metaDataType = "Nil"
)

Variables

View Source
var (
	CatWrap    = ErrorCategory{"Wrap"}    // The error is simply wrapping another error (e.g. when a grpc call returns an error)
	CatSystem  = ErrorCategory{"System"}  // An internal system error (e.g. connection to db failed)
	CatUser    = ErrorCategory{"User"}    // The user (the API caller) did something wrong (e.g. he has no permissions to do this)
	CatForeign = ErrorCategory{"Foreign"} // A foreign error that some component threw (e.g. an unknown mongodb error), happens if we call Wrap(..) on an non-bmerror value
)
View Source
var (
	SevTrace = ErrorSeverity{"Trace"}
	SevDebug = ErrorSeverity{"Debug"}
	SevInfo  = ErrorSeverity{"Info"}
	SevWarn  = ErrorSeverity{"Warn"}
	SevErr   = ErrorSeverity{"Err"}
	SevFatal = ErrorSeverity{"Fatal"}
)
View Source
var (
	TypeInternal = ErrorType{"Internal"}
)

Functions

func Init

func Init(cfg ErrorPackageConfigInit)

Init initializes the exerr packages Must be called at the program start, before (!) any errors Is not thread-safe

func RegisterListener

func RegisterListener(l Listener)

Types

type AnyWrap

type AnyWrap struct {
	Type    string
	Json    string
	IsError bool
	IsNil   bool
}

func (AnyWrap) Serialize

func (w AnyWrap) Serialize() string

func (AnyWrap) String

func (w AnyWrap) String() string

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func Get

func Get(err error) *Builder

func New

func New(t ErrorType, msg string) *Builder

func Wrap

func Wrap(err error, msg string) *Builder

func (*Builder) Any

func (b *Builder) Any(key string, val any) *Builder

func (*Builder) Bool

func (b *Builder) Bool(key string, val bool) *Builder

func (*Builder) Build

func (b *Builder) Build() error

Build creates a new error, ready to pass up the stack If the errors is not SevWarn or SevInfo it gets also logged (in short form, without stacktrace) onto stdout

func (*Builder) Bytes

func (b *Builder) Bytes(key string, val []byte) *Builder

func (*Builder) CallListener

func (b *Builder) CallListener(m Method)

func (*Builder) Dur

func (b *Builder) Dur(key string, val time.Duration) *Builder

func (*Builder) Err

func (b *Builder) Err() *Builder

Err changes the Severity to ERROR (default) The error will be:

  • On Build():

  • Short-Logged as Err

  • On Print():

  • Logged as Err

  • Send to the error-service

  • On Output():

  • Logged as Err

  • Send to the error-service

func (*Builder) Errs

func (b *Builder) Errs(key string, val []error) *Builder

func (*Builder) Fatal

func (b *Builder) Fatal()

Fatal prints the error and terminates the program If the error is SevErr we also send it to the error-service

func (*Builder) Float32

func (b *Builder) Float32(key string, val float32) *Builder

func (*Builder) Float64

func (b *Builder) Float64(key string, val float64) *Builder

func (*Builder) Format

func (b *Builder) Format(level LogPrintLevel) string

func (*Builder) GinReq

func (b *Builder) GinReq(ctx context.Context, g *gin.Context, req *http.Request) *Builder

func (*Builder) Id

func (b *Builder) Id(key string, val fmt.Stringer) *Builder

func (*Builder) Info

func (b *Builder) Info() *Builder

Info changes the Severity to INFO The error will be:

  • On Build():

  • -(nothing)-

  • On Print():

  • -(nothing)-

  • On Output():

  • -(nothing)-

func (*Builder) Int

func (b *Builder) Int(key string, val int) *Builder

func (*Builder) Int16

func (b *Builder) Int16(key string, val int16) *Builder

func (*Builder) Int32

func (b *Builder) Int32(key string, val int32) *Builder

func (*Builder) Int64

func (b *Builder) Int64(key string, val int64) *Builder

func (*Builder) Int8

func (b *Builder) Int8(key string, val int8) *Builder

func (*Builder) Interface

func (b *Builder) Interface(key string, val interface{}) *Builder

func (*Builder) Ints

func (b *Builder) Ints(key string, val []int) *Builder

func (*Builder) Ints32

func (b *Builder) Ints32(key string, val []int32) *Builder

func (*Builder) ObjectID

func (b *Builder) ObjectID(key string, val primitive.ObjectID) *Builder

func (*Builder) Output

func (b *Builder) Output(ctx context.Context, g *gin.Context)

Output prints the error onto the gin stdout. The error also gets printed to stdout/stderr If the error is SevErr|SevFatal we also send it to the error-service

func (*Builder) Print

func (b *Builder) Print()

Print prints the error If the error is SevErr we also send it to the error-service

func (*Builder) Stack

func (b *Builder) Stack() *Builder

func (*Builder) Str

func (b *Builder) Str(key string, val string) *Builder

func (*Builder) StrPtr

func (b *Builder) StrPtr(key string, val *string) *Builder

func (*Builder) Strs

func (b *Builder) Strs(key string, val []string) *Builder

func (*Builder) System

func (b *Builder) System() *Builder

func (*Builder) Time

func (b *Builder) Time(key string, val time.Time) *Builder

func (*Builder) Type

func (b *Builder) Type(key string, cls interface{}) *Builder

func (*Builder) User

func (b *Builder) User() *Builder

User sets the Category to CatUser

Errors with category

func (*Builder) Warn

func (b *Builder) Warn() *Builder

Warn changes the Severity to WARN The error will be:

  • On Build():

  • -(nothing)-

  • On Print():

  • Short-Logged as Warn

  • On Output():

  • Logged as Warn

func (*Builder) WithMessage

func (b *Builder) WithMessage(msg string) *Builder

func (*Builder) WithStatuscode

func (b *Builder) WithStatuscode(status int) *Builder

func (*Builder) WithType

func (b *Builder) WithType(t ErrorType) *Builder

type ErrorCategory

type ErrorCategory struct{ Category string }

type ErrorPackageConfig

type ErrorPackageConfig struct {
	ZeroLogTraces   bool        // autom print zerolog logs on CreateError
	RecursiveErrors bool        // errors contains their Origin-Error
	Types           []ErrorType // all available error-types
}

type ErrorPackageConfigInit

type ErrorPackageConfigInit struct {
	LogTraces       bool
	RecursiveErrors bool
	InitTypes       func(_ func(_ string) ErrorType)
}

type ErrorSeverity

type ErrorSeverity struct{ Severity string }

type ErrorType

type ErrorType struct{ Key string }

type ExErr

type ExErr struct {
	UniqueID string `json:"uniqueID"`

	Timestamp time.Time     `json:"timestamp"`
	Category  ErrorCategory `json:"category"`
	Severity  ErrorSeverity `json:"severity"`
	Type      ErrorType     `json:"type"`

	Message string `json:"message"`
	Caller  string `json:"caller"`

	OriginalError *ExErr

	Meta MetaMap `json:"meta"`
}

func (ExErr) Error

func (ee ExErr) Error() string

func (ExErr) Is

func (ee ExErr) Is(err error) bool

func (ExErr) Unwrap

func (ee ExErr) Unwrap() error

type IDWrap

type IDWrap struct {
	Type  string
	Value string
	IsNil bool
}

func (IDWrap) Serialize

func (w IDWrap) Serialize() string

func (IDWrap) String

func (w IDWrap) String() string

type Listener

type Listener = func(method Method, v ExErr)

type MetaMap

type MetaMap map[string]MetaValue

func (MetaMap) Any

func (mm MetaMap) Any() bool

func (MetaMap) Apply

func (mm MetaMap) Apply(evt *zerolog.Event) *zerolog.Event

func (MetaMap) FormatMultiLine

func (mm MetaMap) FormatMultiLine(indentFront string, indentKeys string, maxLenValue int) string

func (MetaMap) FormatOneLine

func (mm MetaMap) FormatOneLine(singleMaxLen int) string

func (MetaMap) ToProto

func (mm MetaMap) ToProto() []*spbmodels.CustomError_MetaValue

type MetaValue

type MetaValue struct {
	DataType metaDataType `json:"dataType"`
	Value    interface{}  `json:"value"`
}

func (MetaValue) Apply

func (v MetaValue) Apply(key string, evt *zerolog.Event) *zerolog.Event

func (*MetaValue) Deserialize

func (v *MetaValue) Deserialize(value string, datatype metaDataType) error

func (MetaValue) MarshalBSON

func (v MetaValue) MarshalBSON() ([]byte, error)

func (MetaValue) MarshalJSON

func (v MetaValue) MarshalJSON() ([]byte, error)

func (MetaValue) SerializeValue

func (v MetaValue) SerializeValue() (string, error)

func (MetaValue) ShortString

func (v MetaValue) ShortString(lim int) string

func (*MetaValue) UnmarshalBSON

func (v *MetaValue) UnmarshalBSON(bytes []byte) error

func (*MetaValue) UnmarshalJSON

func (v *MetaValue) UnmarshalJSON(data []byte) error

func (MetaValue) ValueString

func (v MetaValue) ValueString() string

type Method

type Method string
const (
	MethodOutput Method = "OUTPUT"
	MethodPrint  Method = "PRINT"
	MethodBuild  Method = "BUILD"
	MethodFatal  Method = "FATAL"
)

Jump to

Keyboard shortcuts

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