Documentation ¶
Index ¶
- Constants
- Variables
- func HasSourceMessage(e error, msg string) bool
- func Init(cfg ErrorPackageConfigInit)
- func Initialized() bool
- func IsFrom(e error, original error) bool
- func IsType(err error, errType ErrorType) bool
- func MessageMatch(e error, matcher func(string) bool) bool
- func OriginalError(e error) error
- func RegisterListener(l Listener)
- func UniqueID(v error) *string
- type AnyWrap
- type Builder
- func (b *Builder) Any(key string, val any) *Builder
- func (b *Builder) Bool(key string, val bool) *Builder
- func (b *Builder) Build(ctxs ...context.Context) error
- func (b *Builder) Bytes(key string, val []byte) *Builder
- func (b *Builder) CtxData(method Method, ctx context.Context) *Builder
- func (b *Builder) Dur(key string, val time.Duration) *Builder
- func (b *Builder) Enum(key string, val enums.Enum) *Builder
- func (b *Builder) Err() *Builder
- func (b *Builder) Errs(key string, val []error) *Builder
- func (b *Builder) Extra(key string, val any) *Builder
- func (b *Builder) Fatal(ctxs ...context.Context)
- func (b *Builder) Float32(key string, val float32) *Builder
- func (b *Builder) Float64(key string, val float64) *Builder
- func (b *Builder) Format(level LogPrintLevel) string
- func (b *Builder) GinReq(ctx context.Context, g *gin.Context, req *http.Request) *Builder
- func (b *Builder) Id(key string, val fmt.Stringer) *Builder
- func (b *Builder) Info() *Builder
- func (b *Builder) Int(key string, val int) *Builder
- func (b *Builder) Int16(key string, val int16) *Builder
- func (b *Builder) Int32(key string, val int32) *Builder
- func (b *Builder) Int64(key string, val int64) *Builder
- func (b *Builder) Int8(key string, val int8) *Builder
- func (b *Builder) Interface(key string, val interface{}) *Builder
- func (b *Builder) Ints(key string, val []int) *Builder
- func (b *Builder) Ints32(key string, val []int32) *Builder
- func (b *Builder) NoLog() *Builder
- func (b *Builder) ObjectID(key string, val primitive.ObjectID) *Builder
- func (b *Builder) Output(ctx context.Context, g *gin.Context)
- func (b *Builder) Print(ctxs ...context.Context) Proxy
- func (b *Builder) Stack() *Builder
- func (b *Builder) Str(key string, val string) *Builder
- func (b *Builder) StrPtr(key string, val *string) *Builder
- func (b *Builder) Stringer(key string, val fmt.Stringer) *Builder
- func (b *Builder) Strs(key string, val []string) *Builder
- func (b *Builder) System() *Builder
- func (b *Builder) Time(key string, val time.Time) *Builder
- func (b *Builder) Type(key string, cls interface{}) *Builder
- func (b *Builder) User() *Builder
- func (b *Builder) Warn() *Builder
- func (b *Builder) WithMessage(msg string) *Builder
- func (b *Builder) WithStatuscode(status int) *Builder
- func (b *Builder) WithType(t ErrorType) *Builder
- type EnumWrap
- type ErrorCategory
- func (e ErrorCategory) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func (e ErrorCategory) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (e ErrorCategory) MarshalJSON() ([]byte, error)
- func (e *ErrorCategory) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
- func (e *ErrorCategory) UnmarshalJSON(bytes []byte) error
- type ErrorPackageConfig
- type ErrorPackageConfigInit
- type ErrorSeverity
- func (e ErrorSeverity) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func (e ErrorSeverity) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (e ErrorSeverity) MarshalJSON() ([]byte, error)
- func (e *ErrorSeverity) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
- func (e *ErrorSeverity) UnmarshalJSON(bytes []byte) error
- type ErrorType
- func (e ErrorType) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
- func (e ErrorType) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (e ErrorType) MarshalJSON() ([]byte, error)
- func (e *ErrorType) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
- func (e *ErrorType) UnmarshalJSON(bytes []byte) error
- type ExErr
- func (ee *ExErr) As(target any) bool
- func (ee *ExErr) CallListener(m Method)
- func (ee *ExErr) Depth() int
- func (ee *ExErr) Error() string
- func (ee *ExErr) FormatLog(lvl LogPrintLevel) string
- func (ee *ExErr) GetExtra(key string) (any, bool)
- func (ee *ExErr) GetMeta(key string) (any, bool)
- func (ee *ExErr) GetMetaBool(key string) (bool, bool)
- func (ee *ExErr) GetMetaFloat32(key string) (float32, bool)
- func (ee *ExErr) GetMetaFloat64(key string) (float64, bool)
- func (ee *ExErr) GetMetaInt(key string) (int, bool)
- func (ee *ExErr) GetMetaString(key string) (string, bool)
- func (ee *ExErr) GetMetaTime(key string) (time.Time, bool)
- func (ee *ExErr) Is(e error) bool
- func (ee *ExErr) Log(evt *zerolog.Event)
- func (ee *ExErr) Output(g *gin.Context)
- func (ee *ExErr) RecursiveCategory() ErrorCategory
- func (ee *ExErr) RecursiveMessage() string
- func (ee *ExErr) RecursiveMeta(key string) *MetaValue
- func (ee *ExErr) RecursiveStatuscode() *int
- func (ee *ExErr) RecursiveType() ErrorType
- func (ee *ExErr) ShortLog(evt *zerolog.Event)
- func (ee *ExErr) ToAPIJson(applyExtendListener bool, includeWrappedErrors bool, includeMetaFields bool) langext.H
- func (ee *ExErr) ToDefaultAPIJson() (string, error)
- func (ee *ExErr) UniqueIDs() []string
- func (ee *ExErr) Unwrap() error
- type IDWrap
- type Listener
- type LogPrintLevel
- type MetaMap
- type MetaValue
- func (v MetaValue) Apply(key string, evt *zerolog.Event, limitLen *int) *zerolog.Event
- func (v *MetaValue) Deserialize(value string, datatype metaDataType) error
- func (v MetaValue) MarshalBSON() ([]byte, error)
- func (v MetaValue) MarshalJSON() ([]byte, error)
- func (v MetaValue) SerializeValue() (string, error)
- func (v MetaValue) ShortString(lim int) string
- func (v *MetaValue) UnmarshalBSON(bytes []byte) error
- func (v *MetaValue) UnmarshalJSON(data []byte) error
- func (v MetaValue) ValueString() string
- type Method
- type Proxy
Constants ¶
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" MDTEnum metaDataType = "Enum" )
Variables ¶
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 )
var ( SevTrace = ErrorSeverity{"Trace"} SevDebug = ErrorSeverity{"Debug"} SevInfo = ErrorSeverity{"Info"} SevWarn = ErrorSeverity{"Warn"} SevErr = ErrorSeverity{"Err"} SevFatal = ErrorSeverity{"Fatal"} )
var ( TypeInternal = NewType("INTERNAL_ERROR", langext.Ptr(500)) TypePanic = NewType("PANIC", langext.Ptr(500)) TypeNotImplemented = NewType("NOT_IMPLEMENTED", langext.Ptr(500)) TypeAssert = NewType("ASSERT", langext.Ptr(500)) TypeMongoQuery = NewType("MONGO_QUERY", langext.Ptr(500)) TypeCursorTokenDecode = NewType("CURSOR_TOKEN_DECODE", langext.Ptr(500)) TypeMongoFilter = NewType("MONGO_FILTER", langext.Ptr(500)) TypeMongoReflection = NewType("MONGO_REFLECTION", langext.Ptr(500)) TypeMongoInvalidOpt = NewType("MONGO_INVALIDOPT", langext.Ptr(500)) TypeSQLQuery = NewType("SQL_QUERY", langext.Ptr(500)) TypeSQLBuild = NewType("SQL_BUILD", langext.Ptr(500)) TypeSQLDecode = NewType("SQL_DECODE", langext.Ptr(500)) TypeWrap = NewType("Wrap", nil) TypeBindFailURI = NewType("BINDFAIL_URI", langext.Ptr(400)) TypeBindFailQuery = NewType("BINDFAIL_QUERY", langext.Ptr(400)) TypeBindFailJSON = NewType("BINDFAIL_JSON", langext.Ptr(400)) TypeBindFailFormData = NewType("BINDFAIL_FORMDATA", langext.Ptr(400)) TypeBindFailHeader = NewType("BINDFAIL_HEADER", langext.Ptr(400)) TypeMarshalEntityID = NewType("MARSHAL_ENTITY_ID", langext.Ptr(400)) TypeInvalidCSID = NewType("INVALID_CSID", langext.Ptr(400)) TypeGoogleStatuscode = NewType("GOOGLE_STATUSCODE", langext.Ptr(400)) TypeGoogleResponse = NewType("GOOGLE_RESPONSE", langext.Ptr(400)) TypeAuthFailed = NewType("AUTH_FAILED", langext.Ptr(401)) TypeInvalidImage = NewType("IMAGEEXT_INVALID_IMAGE", langext.Ptr(400)) TypeInvalidMimeType = NewType("IMAGEEXT_INVALID_MIMETYPE", langext.Ptr(400)) )
var AllCategories = []ErrorCategory{CatWrap, CatSystem, CatUser, CatForeign}
var AllSeverities = []ErrorSeverity{SevTrace, SevDebug, SevInfo, SevWarn, SevErr, SevFatal}
Functions ¶
func HasSourceMessage ¶ added in v0.0.188
HasSourceMessage tests if the supplied error stems originally from an error with the message msg
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 Initialized ¶ added in v0.0.325
func Initialized() bool
func OriginalError ¶ added in v0.0.510
OriginalError returns the lowest level error, probably the original/external error that was originally wrapped
func RegisterListener ¶
func RegisterListener(l Listener)
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) Build ¶
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 Can be gloablly configured with ZeroLogErrTraces and ZeroLogAllTraces Can be locally suppressed with Builder.NoLog()
func (*Builder) Err ¶
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) Extra ¶ added in v0.0.490
Extra adds additional data to the error this is not like the other metadata (like Id(), Str(), etc) this data is public and will be printed/outputted
func (*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) Format ¶
func (b *Builder) Format(level LogPrintLevel) string
func (*Builder) Info ¶
Info changes the Severity to INFO The error will be:
On Build():
-(nothing)-
On Print():
-(nothing)-
On Output():
-(nothing)-
func (*Builder) Output ¶
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 ¶
Print prints the error If the error is SevErr we also send it to the error-service
func (*Builder) Warn ¶
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 (*Builder) WithStatuscode ¶
type EnumWrap ¶ added in v0.0.235
type ErrorCategory ¶
type ErrorCategory struct{ Category string }
func (ErrorCategory) DecodeValue ¶ added in v0.0.455
func (e ErrorCategory) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
func (ErrorCategory) MarshalBSONValue ¶ added in v0.0.455
func (e ErrorCategory) MarshalBSONValue() (bsontype.Type, []byte, error)
func (ErrorCategory) MarshalJSON ¶ added in v0.0.455
func (e ErrorCategory) MarshalJSON() ([]byte, error)
func (*ErrorCategory) UnmarshalBSONValue ¶ added in v0.0.455
func (e *ErrorCategory) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
func (*ErrorCategory) UnmarshalJSON ¶ added in v0.0.455
func (e *ErrorCategory) UnmarshalJSON(bytes []byte) error
type ErrorPackageConfig ¶
type ErrorPackageConfig struct { ZeroLogErrTraces bool // autom print zerolog logs on .Build() (for SevErr and SevFatal) ZeroLogAllTraces bool // autom print zerolog logs on .Build() (for all Severities) RecursiveErrors bool // errors contains their Origin-Error ExtendedGinOutput bool // Log extended data (trace, meta, ...) to gin in err.Output() IncludeMetaInGinOutput bool // Log meta fields ( from e.g. `.Str(key, val).Build()` ) to gin in err.Output() ExtendGinOutput func(err *ExErr, json map[string]any) // (Optionally) extend the gin output with more fields ExtendGinDataOutput func(err *ExErr, depth int, json map[string]any) // (Optionally) extend the gin `__data` output with more fields DisableErrorWrapping bool // Disables the exerr.Wrap()...Build() function - will always return the original error ZeroLogErrGinOutput bool // autom print zerolog logs on ginext.Error() / .Output(gin) (for SevErr and SevFatal) ZeroLogAllGinOutput bool // autom print zerolog logs on ginext.Error() / .Output(gin) (for all Severities) ExtendGinMeta func(ctx context.Context, b *Builder, g *gin.Context, req *http.Request) // (Optionally) extend the final error meta values with additional data from the gin context (a few are automatically added, here more can be included) ExtendContextMeta func(b *Builder, method Method, dctx context.Context) // (Optionally) extend the final error meta values with additional data from the context (a few are automatically added, here more can be included) ZeroLogger zerolog.Logger // The logger used to print exerr log messages }
type ErrorPackageConfigInit ¶
type ErrorPackageConfigInit struct { ZeroLogErrTraces *bool ZeroLogAllTraces *bool RecursiveErrors *bool ExtendedGinOutput *bool IncludeMetaInGinOutput *bool ExtendGinOutput func(err *ExErr, json map[string]any) ExtendGinDataOutput func(err *ExErr, depth int, json map[string]any) DisableErrorWrapping *bool ZeroLogErrGinOutput *bool ZeroLogAllGinOutput *bool ExtendGinMeta func(ctx context.Context, b *Builder, g *gin.Context, req *http.Request) ExtendContextMeta func(b *Builder, method Method, dctx context.Context) ZeroLogger *zerolog.Logger }
type ErrorSeverity ¶
type ErrorSeverity struct{ Severity string }
func (ErrorSeverity) DecodeValue ¶ added in v0.0.455
func (e ErrorSeverity) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
func (ErrorSeverity) MarshalBSONValue ¶ added in v0.0.455
func (e ErrorSeverity) MarshalBSONValue() (bsontype.Type, []byte, error)
func (ErrorSeverity) MarshalJSON ¶ added in v0.0.455
func (e ErrorSeverity) MarshalJSON() ([]byte, error)
func (*ErrorSeverity) UnmarshalBSONValue ¶ added in v0.0.455
func (e *ErrorSeverity) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
func (*ErrorSeverity) UnmarshalJSON ¶ added in v0.0.455
func (e *ErrorSeverity) UnmarshalJSON(bytes []byte) error
type ErrorType ¶
func ListRegisteredTypes ¶ added in v0.0.362
func ListRegisteredTypes() []ErrorType
func (ErrorType) DecodeValue ¶ added in v0.0.455
func (e ErrorType) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error
func (ErrorType) MarshalBSONValue ¶ added in v0.0.455
func (ErrorType) MarshalJSON ¶ added in v0.0.455
func (*ErrorType) UnmarshalBSONValue ¶ added in v0.0.455
func (*ErrorType) UnmarshalJSON ¶ added in v0.0.455
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"` StatusCode *int `json:"statusCode"` Message string `json:"message"` WrappedErrType string `json:"wrappedErrType"` WrappedErr any `json:"-"` Caller string `json:"caller"` OriginalError *ExErr `json:"originalError"` Extra map[string]any `json:"extra"` Meta MetaMap `json:"meta"` }
func (*ExErr) CallListener ¶ added in v0.0.361
func (*ExErr) FormatLog ¶ added in v0.0.188
func (ee *ExErr) FormatLog(lvl LogPrintLevel) string
func (*ExErr) GetMeta ¶ added in v0.0.356
GetMeta returns the meta value with the specified key this method recurses through all wrapped errors and returns the first matching meta value
func (*ExErr) GetMetaFloat32 ¶ added in v0.0.357
func (*ExErr) GetMetaFloat64 ¶ added in v0.0.357
func (*ExErr) GetMetaString ¶ added in v0.0.357
GetMetaString functions the same as GetMeta, but returns false if the type does not match
func (*ExErr) GetMetaTime ¶ added in v0.0.357
func (*ExErr) RecursiveCategory ¶ added in v0.0.188
func (ee *ExErr) RecursiveCategory() ErrorCategory
RecursiveCategory returns the ErrorCategory to use = first error (top-down) that has a statuscode set
func (*ExErr) RecursiveMessage ¶ added in v0.0.188
RecursiveMessage returns the message to show = first error (top-down) that is not foreign/empty = lowest level error (that is not empty) = fallback to self.message
func (*ExErr) RecursiveMeta ¶ added in v0.0.194
RecursiveMeta searches (top-down) for teh first error that has a meta value with teh specified key and returns its value (or nil)
func (*ExErr) RecursiveStatuscode ¶ added in v0.0.188
RecursiveStatuscode returns the HTTP Statuscode to use = first error (top-down) that has a statuscode set
func (*ExErr) RecursiveType ¶ added in v0.0.188
RecursiveType returns the statuscode to use = first error (top-down) that is not wrapping/empty
func (*ExErr) ToAPIJson ¶ added in v0.0.215
func (ee *ExErr) ToAPIJson(applyExtendListener bool, includeWrappedErrors bool, includeMetaFields bool) langext.H
ToAPIJson converts the ExError to a json object (the same object as used in the Output(gin) method)
Parameters:
- [applyExtendListener]: if false the pkgconfig.ExtendGinOutput / pkgconfig.ExtendGinDataOutput will not be applied
- [includeWrappedErrors]: if false we do not include the recursive/wrapped errors in `__data`
- [includeMetaFields]: if true we also include meta-values (aka from `.Str(key, value).Build()`), needs includeWrappedErrors=true
func (*ExErr) ToDefaultAPIJson ¶ added in v0.0.349
type LogPrintLevel ¶ added in v0.0.188
type LogPrintLevel string
const ( LogPrintFull LogPrintLevel = "Full" LogPrintOverview LogPrintLevel = "Overview" LogPrintShort LogPrintLevel = "Short" )
type MetaValue ¶
type MetaValue struct { DataType metaDataType `json:"dataType"` Value interface{} `json:"value"` }