Explicit log callback

This commit is contained in:
Magnus Åhall 2024-04-05 08:30:30 +02:00
parent c66ba0e169
commit 1154fd39a2

11
pkg.go
View File

@ -10,16 +10,17 @@ import (
type Error struct { type Error struct {
Wrapped error Wrapped error
ErrStr string // wrapped error isn't necessarily json encodable ErrStr string // wrapped error isn't necessarily json encodable
Code string `json:",omitempty"` Code string
File string File string
Line int Line int
Data any `json:",omitempty"` Data any
} }
type CodableError interface { type CodableError interface {
error error
WithCode(string) CodableError WithCode(string) CodableError
WithData(any) CodableError WithData(any) CodableError
Log() CodableError
} }
type LogCallback func(Error) type LogCallback func(Error)
@ -78,7 +79,6 @@ func create(err error, data interface{}) *Error {
Data: data, Data: data,
} }
callback(wrapped)
return &wrapped return &wrapped
} }
@ -114,3 +114,8 @@ func (e *Error) WithData(data any) CodableError {
e.Data = data e.Data = data
return e return e
} }
func (e *Error) Log() CodableError {
callback(*e)
return e
}