Added error string and better data default
This commit is contained in:
parent
776917b9c0
commit
16d41de1ae
7
pkg.go
7
pkg.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user