-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
R4R: Parsed Err msgs #2119
R4R: Parsed Err msgs #2119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ package types | |
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
cmn "github.com/tendermint/tendermint/libs/common" | ||
|
||
"github.com/cosmos/cosmos-sdk/wire" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
) | ||
|
||
|
@@ -225,7 +227,11 @@ func (err *sdkError) TraceSDK(format string, args ...interface{}) Error { | |
// Implements ABCIError. | ||
// Overrides err.Error.Error(). | ||
func (err *sdkError) Error() string { | ||
return fmt.Sprintf("Error{%d:%d,%#v}", err.codespace, err.code, err.cmnError) | ||
return fmt.Sprintf(`ERROR: | ||
Codespace: %d | ||
Code: %d | ||
Message: %#v | ||
`, err.codespace, err.code, parseCmnError(err.cmnError.Error())) | ||
} | ||
|
||
// Implements ABCIError. | ||
|
@@ -245,13 +251,20 @@ func (err *sdkError) Code() CodeType { | |
|
||
// Implements ABCIError. | ||
func (err *sdkError) ABCILog() string { | ||
return fmt.Sprintf(`=== ABCI Log === | ||
Codespace: %v | ||
Code: %v | ||
ABCICode: %v | ||
Error: %#v | ||
=== /ABCI Log === | ||
`, err.codespace, err.code, err.ABCICode(), err.cmnError) | ||
cdc := wire.NewCodec() | ||
parsedErrMsg := parseCmnError(err.cmnError.Error()) | ||
jsonErr := humanReadableError{ | ||
Codespace: err.codespace, | ||
Code: err.code, | ||
ABCICode: err.ABCICode(), | ||
Message: parsedErrMsg, | ||
} | ||
bz, er := cdc.MarshalJSON(jsonErr) | ||
if er != nil { | ||
panic(er) | ||
} | ||
stringifiedJSON := string(bz) | ||
return stringifiedJSON | ||
} | ||
|
||
func (err *sdkError) Result() Result { | ||
|
@@ -268,3 +281,18 @@ func (err *sdkError) QueryResult() abci.ResponseQuery { | |
Log: err.ABCILog(), | ||
} | ||
} | ||
|
||
func parseCmnError(err string) string { | ||
if idx := strings.Index(err, "{"); idx != -1 { | ||
err = err[idx+1 : len(err)-1] | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a good way of doing this. This means when someone comes around to update the sdk to the next tm version, they won't see a break here, which means were more likely to have this legacy code laying around forever. It should have been something that will break, with a comment for how to upgrade imo. @cwgoes when we have multiple people reviewing can we wait a bit between last update and merge? (Timezones meant I didn't see it between last update and merge) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally I agree - @fedekunze didn't want to wait for the Tendermint PR, and this is blocking downstream. This could indeed be written to break intentionally. I think tracking the necessary fix in an issue is fine too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return err | ||
} | ||
|
||
// nolint | ||
type humanReadableError struct { | ||
Codespace CodespaceType `json:"codespace"` | ||
Code CodeType `json:"code"` | ||
ABCICode ABCICodeType `json:"abci_code"` | ||
Message string `json:"message"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a suboptimal way to parse this, we could have just had a better string method on cmn.error (For tendermint pr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will open a separate PR for tendermint as well to change
cmn.Error.Error()