From 1154fd39a2be5419c14cd15662a0aee3cfcd6c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20=C3=85hall?= Date: Fri, 5 Apr 2024 08:30:30 +0200 Subject: [PATCH] Explicit log callback --- pkg.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 +}