Skip to content
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

Merged
merged 5 commits into from
Aug 23, 2018
Merged

R4R: Parsed Err msgs #2119

merged 5 commits into from
Aug 23, 2018

Conversation

fedekunze
Copy link
Collaborator

Closes #2044 and luniehq/lunie#1131

New error formatting:

  • err.Error():
ERROR:
Codespace: 1
Code: 9
Message: "unknown address"

ERROR:
Codespace: 1
Code: 10
Message: "insufficient coins"
  • err.ABCILog():
{"codespace":1,"code":9,"abci_code":65545,"message":"unknown address"}
{"codespace":1,"code":10,"abci_code":65546,"message":"insufficient coins"}

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • reviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Aug 22, 2018

Codecov Report

Merging #2119 into develop will increase coverage by 1.63%.
The diff coverage is n/a.

@@             Coverage Diff             @@
##           develop    #2119      +/-   ##
===========================================
+ Coverage     62.2%   63.83%   +1.63%     
===========================================
  Files          115      113       -2     
  Lines         6874     6684     -190     
===========================================
- Hits          4276     4267       -9     
+ Misses        2314     2133     -181     
  Partials       284      284

types/errors.go Outdated
Error: %#v
=== /ABCI Log ===
`, err.codespace, err.code, err.ABCICode(), err.cmnError)
parsedErrMsg := parseCmnError(err.cmnError.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm do we want to change this upstream instead (or additionally)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cwgoes you mean moving it to another util folder and export/import it ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean changing the cmn.Error default format

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that cmn.Error is our own struct, we should totally change this there imo. We can merge this for now, and fix on a latrer tm release

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can change it as well, but that would go on a separate PR for tendermint

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ValarDragon just updated the parseCmnError function so that once that we update cmn.Error.Error() on Tm it doesn't break the SDK code

types/errors.go Outdated
`, err.codespace, err.code, err.ABCICode(), err.cmnError)
parsedErrMsg := parseCmnError(err.cmnError.Error())
jsonErr := newHumanReadableError(err.codespace, err.code, err.ABCICode(), parsedErrMsg)
bz, er := json.Marshal(jsonErr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the Amino JSON marshal here? Keeps things more consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use must marshal json

Copy link
Collaborator Author

@fedekunze fedekunze Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no MustMarshalJSON function @ValarDragon . I'll just use cdc.MarshalJSON

PENDING.md Outdated
* [x/auth] Signature verification's gas cost now accounts for pubkey type. [#2046](https://github.com/tendermint/tendermint/pull/2046)

* SDK
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
* [types] \#2119 Parsed error messages and ABCI log errors to make them more human readable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be considered a breaking change, since it may break certain automation scripts?

types/errors.go Outdated
Error: %#v
=== /ABCI Log ===
`, err.codespace, err.code, err.ABCICode(), err.cmnError)
parsedErrMsg := parseCmnError(err.cmnError.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that cmn.Error is our own struct, we should totally change this there imo. We can merge this for now, and fix on a latrer tm release

types/errors.go Outdated
`, err.codespace, err.code, err.ABCICode(), err.cmnError)
parsedErrMsg := parseCmnError(err.cmnError.Error())
jsonErr := newHumanReadableError(err.codespace, err.code, err.ABCICode(), parsedErrMsg)
bz, er := json.Marshal(jsonErr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also use must marshal json

@@ -268,3 +275,25 @@ func (err *sdkError) QueryResult() abci.ResponseQuery {
Log: err.ABCILog(),
}
}

func parseCmnError(err string) string {
Copy link
Contributor

@ValarDragon ValarDragon Aug 23, 2018

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)

Copy link
Collaborator Author

@fedekunze fedekunze Aug 23, 2018

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

types/errors.go Outdated
Message string `json:"message"`
}

func newHumanReadableError(codespace CodespaceType, code CodeType, ABCICode ABCICodeType, msg string) HumanReadableError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new method seems unnecessary here.

types/errors.go Outdated
}

// nolint
type HumanReadableError struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not export this, it shouldn't be used anywhere else.

Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, let's remove parseCmnError when we update upstream

@cwgoes cwgoes merged commit aa82f6f into develop Aug 23, 2018
@cwgoes cwgoes deleted the fedekunze/2044-JSON-err-msgs branch August 23, 2018 11:55
@faboweb
Copy link
Contributor

faboweb commented Aug 23, 2018

Good work @fedekunze

@fedekunze
Copy link
Collaborator Author

Thanks @faboweb ! 🙌

func parseCmnError(err string) string {
if idx := strings.Index(err, "{"); idx != -1 {
err = err[idx+1 : len(err)-1]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

@cwgoes cwgoes Aug 23, 2018

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants