Skip to content

Commit cdf856f

Browse files
lysucoocood
authored andcommitted
add NewNoStackError support (#13)
1 parent 8abfc13 commit cdf856f

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

juju_adaptor.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func Annotatef(err error, format string, args ...interface{}) error {
5555
}
5656
}
5757

58+
var emptyStack stack
59+
60+
// NewNoStackError creates error without error stack
61+
// later duplicate trace will no longer generate Stack too.
62+
func NewNoStackError(msg string) error {
63+
return &fundamental{
64+
msg: msg,
65+
stack: &emptyStack,
66+
}
67+
}
68+
5869
// ErrorStack will format a stack trace if it is available, otherwise it will be Error()
5970
// If the error is nil, the empty string is returned
6071
// Note that this just calls fmt.Sprintf("%+v", err)

stack_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,13 @@ func TestNewStack(t *testing.T) {
287287
t.Errorf("NewStack(): want: %v, got: %+v", "testing.tRunner", gotFirst)
288288
}
289289
}
290+
291+
func TestSuspendStackError(t *testing.T) {
292+
err := NewNoStackError("test error")
293+
err = Trace(err)
294+
err = Trace(err)
295+
result := fmt.Sprintf("%+v", err)
296+
if result != "test error" {
297+
t.Errorf("NewNoStackError(): want %s, got %v", "test error", result)
298+
}
299+
}

0 commit comments

Comments
 (0)