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 {
|
type Error struct {
|
||||||
Wrapped error
|
Wrapped error
|
||||||
|
ErrStr string // wrapped error isn't necessarily json encodable
|
||||||
File string
|
File string
|
||||||
Line int
|
Line int
|
||||||
Data interface{}
|
Data interface{} `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LogCallback func(Error)
|
type LogCallback func(Error)
|
||||||
@ -57,9 +58,9 @@ func create(err error, data interface{}) error {
|
|||||||
|
|
||||||
_, file, line, _ := runtime.Caller(2)
|
_, file, line, _ := runtime.Caller(2)
|
||||||
file = file[baseDirLength+1:]
|
file = file[baseDirLength+1:]
|
||||||
|
|
||||||
wrapped := Error{
|
wrapped := Error{
|
||||||
Wrapped: err,
|
Wrapped: err,
|
||||||
|
ErrStr: err.Error(),
|
||||||
File: file,
|
File: file,
|
||||||
Line: line,
|
Line: line,
|
||||||
Data: data,
|
Data: data,
|
||||||
@ -71,7 +72,7 @@ func create(err error, data interface{}) error {
|
|||||||
|
|
||||||
// Wrap wraps an existing error with file and line.
|
// Wrap wraps an existing error with file and line.
|
||||||
func Wrap(err error) error {
|
func Wrap(err error) error {
|
||||||
return create(err, "")
|
return create(err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WrapData(err error, data interface{}) error {
|
func WrapData(err error, data interface{}) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user