Skip to content

Commit

Permalink
add NewNoStackError support (pingcap#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
lysu authored and SwanSpouse committed Jul 14, 2019
1 parent d65ccc9 commit 1063eef
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 @@ -288,6 +288,16 @@ func TestNewStack(t *testing.T) {
}
}

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)
}
}

// a version of runtime.Caller that returns a Frame, not a uintptr.
func caller() Frame {
var pcs [3]uintptr
Expand Down

0 comments on commit 1063eef

Please sign in to comment.