Skip to content

Commit

Permalink
Merge pull request #66 from AilinKid/add_no_stack_errorf
Browse files Browse the repository at this point in the history
error: add no_stack_errorf
  • Loading branch information
AilinKid authored Dec 12, 2023
2 parents b66cddb + f711732 commit 799fae1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions juju_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func NewNoStackError(msg string) error {
}
}

// NewNoStackErrorf creates error with error stack and formats according
// to a format specifier and returns the string as a value that satisfies error.
func NewNoStackErrorf(format string, args ...interface{}) error {
return &fundamental{
msg: fmt.Sprintf(format, args...),
stack: &emptyStack,
}
}

// SuspendStack suspends stack generate for error.
func SuspendStack(err error) error {
if err == nil {
Expand Down
10 changes: 10 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ func TestNewNoStackError(t *testing.T) {
}
}

func TestNewNoStackErrorf(t *testing.T) {
err := NewNoStackErrorf("test error %s", "yes")
err = Trace(err)
err = Trace(err)
result := fmt.Sprintf("%+v", err)
if result != "test error yes" {
t.Errorf("NewNoStackError(): want %s, got %v", "test error", result)
}
}

func TestSuspendError(t *testing.T) {
err := io.EOF
err = SuspendStack(err)
Expand Down

0 comments on commit 799fae1

Please sign in to comment.