Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion types/errors/stacktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,25 @@ func writeSimpleFrame(s io.Writer, f errors.Frame) {
if len(chunks) == 2 {
file = chunks[1]
}
// replace specific file versions in stack trace
file = replacePackageVersionStr(file)
fmt.Fprintf(s, " [%s:%d]", file, line)
}

func replacePackageVersionStr(err string) string {
err = strings.Replace(err, "sei-wasmd@v0.3.11", "sei-wasmd@v0.3.10", 1)
err = strings.Replace(err, "CosmWasm/wasmd@v0.27.0", "sei-protocol/sei-wasmd@v0.3.10", 1)
err = strings.Replace(err, "sei-cosmos@v0.3.67", "sei-cosmos@v0.3.66", 1)
err = strings.Replace(err, "sei-cosmos@v0.3.68", "sei-cosmos@v0.3.66", 1)
return err
}

// Format works like pkg/errors, with additions.
// %s is just the error message
// %+v is the full stack trace
// %v appends a compressed [filename:line] where the error
// was created
//
// was created
//
// Inspired by https://github.com/pkg/errors/blob/v0.8.1/errors.go#L162-L176
func (e *wrappedError) Format(s fmt.State, verb rune) {
Expand Down
24 changes: 24 additions & 0 deletions types/errors/stacktrace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,27 @@ func (s *errorsTestSuite) TestStackTrace() {
s.Require().True(strings.Contains(tinyStack, thisTestSrc))
}
}

func (s *errorsTestSuite) TestReplaceWasmdVersionStr() {
input := "sei-wasmd@v0.3.11/some/path/file.go"
expected := "sei-wasmd@v0.3.10/some/path/file.go"
result := replacePackageVersionStr(input)
s.Require().Equal(expected, result)

input = "CosmWasm/wasmd@v0.27.0/some/path/file.go"
expected = "sei-protocol/sei-wasmd@v0.3.10/some/path/file.go"
result = replacePackageVersionStr(input)
s.Require().Equal(expected, result)
}

func (s *errorsTestSuite) TestReplaceSeiCosmosVersionStr() {
input := "sei-cosmos@v0.3.67/some/path/file.go"
expected := "sei-cosmos@v0.3.66/some/path/file.go"
result := replacePackageVersionStr(input)
s.Require().Equal(expected, result)

input = "sei-cosmos@v0.3.68/some/path/file.go"
expected = "sei-cosmos@v0.3.66/some/path/file.go"
result = replacePackageVersionStr(input)
s.Require().Equal(expected, result)
}
Loading