Added error string and better data default

This commit is contained in:
Magnus Åhall 2024-03-29 09:38:32 +01:00
parent 776917b9c0
commit 16d41de1ae

7
pkg.go
View File

@ -9,9 +9,10 @@ import (
type Error struct {
Wrapped error
ErrStr string // wrapped error isn't necessarily json encodable
File string
Line int
Data interface{}
Data interface{} `json:",omitempty"`
}
type LogCallback func(Error)
@ -57,9 +58,9 @@ func create(err error, data interface{}) error {
_, file, line, _ := runtime.Caller(2)
file = file[baseDirLength+1:]
wrapped := Error{
Wrapped: err,
ErrStr: err.Error(),
File: file,
Line: line,
Data: data,
@ -71,7 +72,7 @@ func create(err error, data interface{}) error {
// Wrap wraps an existing error with file and line.
func Wrap(err error) error {
return create(err, "")
return create(err, nil)
}
func WrapData(err error, data interface{}) error {