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 {
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
}