Documentation ¶
Index ¶
- Constants
- Variables
- func HasSourceMessage(e error, msg string) bool
- func Init(cfg ErrorPackageConfigInit)
- func IsFrom(e error, original error) bool
- func IsType(err error, errType ErrorType) bool
- func MessageMatch(e error, matcher func(string) bool) bool
- func NewType(key string, defStatusCode *int)
- func RegisterListener(l Listener)
- 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() error
- func (b *Builder) Bytes(key string, val []byte) *Builder
- func (b *Builder) CallListener(m Method)
- func (b *Builder) Dur(key string, val time.Duration) *Builder
- func (b *Builder) Err() *Builder
- func (b *Builder) Errs(key string, val []error) *Builder
- func (b *Builder) Fatal()
- 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) ObjectID(key string, val primitive.ObjectID) *Builder
- func (b *Builder) Output(ctx context.Context, g *gin.Context)
- func (b *Builder) Print()
- 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) 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 ErrorCategory
- type ErrorPackageConfig
- type ErrorPackageConfigInit
- type ErrorSeverity
- type ErrorType
- type ExErr
- func (ee *ExErr) Depth() int
- func (ee *ExErr) Error() string
- func (ee *ExErr) FormatLog(lvl LogPrintLevel) string
- 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) RecursiveStatuscode() *int
- func (ee *ExErr) RecursiveType() ErrorType
- func (ee *ExErr) ShortLog(evt *zerolog.Event)
- func (ee *ExErr) Unwrap() error
- type IDWrap
- type Listener
- type LogPrintLevel
- type MetaMap
- type MetaValue
- func (v MetaValue) Apply(key string, evt *zerolog.Event) *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
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" )
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 = ErrorType{"INTERNAL_ERROR", langext.Ptr(500)} TypePanic = ErrorType{"PANIC", langext.Ptr(500)} TypeNotImplemented = ErrorType{"NOT_IMPLEMENTED", langext.Ptr(500)} TypeWrap = ErrorType{"Wrap", nil} TypeBindFailURI = ErrorType{"BINDFAIL_URI", langext.Ptr(400)} TypeBindFailQuery = ErrorType{"BINDFAIL_QUERY", langext.Ptr(400)} TypeBindFailJSON = ErrorType{"BINDFAIL_JSON", langext.Ptr(400)} TypeBindFailFormData = ErrorType{"BINDFAIL_FORMDATA", langext.Ptr(400)} TypeAuthFailed = ErrorType{"AUTH_FAILED", langext.Ptr(401)} )
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 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
func (*Builder) CallListener ¶
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) 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) 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 ¶
func (b *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 ErrorCategory ¶
type ErrorCategory struct{ Category string }
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() ExtendGinOutput func(json map[string]any) // (Optionally) extend the gin output with more fields ExtendGinDataOutput func(json map[string]any) // (Optionally) extend the gin `__data` output with more fields }
type ErrorPackageConfigInit ¶
type ErrorSeverity ¶
type ErrorSeverity struct{ Severity 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"` StatusCode *int `json:"statusCode"` Message string `json:"message"` WrappedErrType string `json:"wrappedErrType"` Caller string `json:"caller"` OriginalError *ExErr Meta MetaMap `json:"meta"` }
func (*ExErr) FormatLog ¶ added in v0.0.188
func (ee *ExErr) FormatLog(lvl LogPrintLevel) string
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 wrapping/foreign/empty
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
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"` }