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