Skip to content

Commit

Permalink
add NewNoStackError support (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and coocood committed May 15, 2019
1 parent 8abfc13 commit cdf856f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions juju_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit cdf856f

Please sign in to comment.