-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7930 from Agoric/mfig-bridge-no-error-stack
fix(cosmos): prevent Golang error wrapping stack frame divergence
- Loading branch information
Showing
7 changed files
with
71 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main_test | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
func TestErrorStackTraces(t *testing.T) { | ||
err := sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "my error %d", 123) | ||
expected := "my error 123: insufficient fee" | ||
|
||
// Check that sdkerrors.Wrapf(...).Error() does not leak stack. | ||
got := err.Error() | ||
if got != expected { | ||
t.Fatalf("err.Error() %q should be %q", got, expected) | ||
} | ||
|
||
// Check that fmt.Errorf("... %s").Error() does not leak stack. | ||
expected = "fail: " + expected | ||
stringified := fmt.Errorf("fail: %s", err) | ||
got = stringified.Error() | ||
if got != expected { | ||
t.Fatalf("stringified.Error() %q should be %q", got, expected) | ||
} | ||
|
||
// Check that fmt.Errorf("... %w").Error() leaks stack. | ||
wrapped := fmt.Errorf("fail: %w", err) | ||
got = wrapped.Error() | ||
expectedAndStack := expected + " [" | ||
if !strings.HasPrefix(got, expectedAndStack) { | ||
t.Fatalf("wrapped.Error() %q should start with %q", got, expectedAndStack) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters