diff --git a/juju_adaptor.go b/juju_adaptor.go index 215b4b5..7abb262 100644 --- a/juju_adaptor.go +++ b/juju_adaptor.go @@ -55,6 +55,17 @@ func Annotatef(err error, format string, args ...interface{}) error { } } +var emptyStack stack + +// NewNoStackError creates error without error stack +// later duplicate trace will no longer generate Stack too. +func NewNoStackError(msg string) error { + return &fundamental{ + msg: msg, + stack: &emptyStack, + } +} + // ErrorStack will format a stack trace if it is available, otherwise it will be Error() // If the error is nil, the empty string is returned // Note that this just calls fmt.Sprintf("%+v", err) diff --git a/stack_test.go b/stack_test.go index 5603425..cf9efad 100644 --- a/stack_test.go +++ b/stack_test.go @@ -287,3 +287,13 @@ func TestNewStack(t *testing.T) { t.Errorf("NewStack(): want: %v, got: %+v", "testing.tRunner", gotFirst) } } + +func TestSuspendStackError(t *testing.T) { + err := NewNoStackError("test error") + err = Trace(err) + err = Trace(err) + result := fmt.Sprintf("%+v", err) + if result != "test error" { + t.Errorf("NewNoStackError(): want %s, got %v", "test error", result) + } +}