renamed CallTrace to CallStack and implemented Error.Stack() method
This commit is contained in:
14
error.go
14
error.go
@ -9,7 +9,7 @@ import (
|
||||
// Error is a wrapper for error with stack trace
|
||||
type Error struct {
|
||||
msg string
|
||||
callTrace *CallTrace
|
||||
callStack *CallStack
|
||||
tmpl *ErrTmpl
|
||||
cause error
|
||||
prev []error
|
||||
@ -19,7 +19,7 @@ type Error struct {
|
||||
func New(msg string) *Error {
|
||||
return &Error{
|
||||
msg: msg,
|
||||
callTrace: Trace(2),
|
||||
callStack: Trace(2),
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ func Wrap(msg string, cause error) *Error {
|
||||
return &Error{
|
||||
msg: msg,
|
||||
cause: cause,
|
||||
callTrace: Trace(2),
|
||||
callStack: Trace(2),
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ func Wrap(msg string, cause error) *Error {
|
||||
func Chain(msg string, errors []error) *Error {
|
||||
return &Error{
|
||||
msg: msg,
|
||||
callTrace: Trace(2),
|
||||
callStack: Trace(2),
|
||||
prev: errors,
|
||||
}
|
||||
}
|
||||
@ -70,6 +70,10 @@ func (e *Error) Message() string {
|
||||
return e.msg
|
||||
}
|
||||
|
||||
func (e *Error) Stack() *CallStack {
|
||||
return e.callStack
|
||||
}
|
||||
|
||||
// Is implements the error equality function used by errors.Is()
|
||||
// It returns true if the error is the same instance or is created using the same ErrTmpl
|
||||
func (e *Error) Is(target error) bool {
|
||||
@ -137,7 +141,7 @@ func printErr(err error, b *strings.Builder) {
|
||||
b.WriteString(": ")
|
||||
b.WriteString(e.msg)
|
||||
b.WriteString("\n")
|
||||
b.WriteString(e.callTrace.String())
|
||||
b.WriteString(e.callStack.String())
|
||||
} else {
|
||||
b.WriteString(errtype(err))
|
||||
b.WriteString(": ")
|
||||
|
Reference in New Issue
Block a user