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

fix: In Keybase GetByAddress, change generic error to NewErrKeyNotFound #1316

Merged

Conversation

jefft0
Copy link
Contributor

@jefft0 jefft0 commented Oct 29, 2023

The Keybase method GetByName returns the specific error ErrKeyNotFound if the key is not found. This is very nice because the GnoMobile API wraps this with a gRPC function and we use keyerror.IsErrKeyNotFound to check the error type and convert it to the gRPC equivalent. But the Keybase method GetByAddress just returns a generic error if the key isn't found. (I assume that it is not intentional to restrict this to a generic error.) This means that the gRPC interface must search the error string for "not found", which is unreliable. We would prefer to use keyerror.IsErrKeyNotFound. Furthermore, GetByNameOrAddress can return an error from either GetByName or GetByAddress. It is preferable to return just one error type for key not found.

This pull request updates GetByAddress to use keyerror.NewErrKeyNotFound with the same error message.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@jefft0 jefft0 requested review from jaekwon and moul as code owners October 29, 2023 14:09
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Oct 29, 2023
@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (199cd29) 47.87% compared to head (b6ec8a6) 47.88%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1316      +/-   ##
==========================================
+ Coverage   47.87%   47.88%   +0.01%     
==========================================
  Files         372      372              
  Lines       63019    63019              
==========================================
+ Hits        30168    30179      +11     
+ Misses      30384    30373      -11     
  Partials     2467     2467              
Files Coverage Δ
tm2/pkg/crypto/keys/keybase.go 50.88% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thehowl thehowl merged commit da05213 into gnolang:master Nov 9, 2023
177 checks passed
moul pushed a commit to moul/gno that referenced this pull request Nov 14, 2023
…nd (gnolang#1316)

The Keybase method `GetByName` [returns the specific
error](https://github.com/gnolang/gno/blob/199cd29584d44812a0aec3606bbff37a320c609a/tm2/pkg/crypto/keys/keybase.go#L184)
`ErrKeyNotFound` if the key is not found. This is very nice because the
GnoMobile API wraps this with a gRPC function and we use
`keyerror.IsErrKeyNotFound` to check the error type and convert it to
the gRPC equivalent. But the Keybase method `GetByAddress` just [returns
a generic
error](https://github.com/gnolang/gno/blob/199cd29584d44812a0aec3606bbff37a320c609a/tm2/pkg/crypto/keys/keybase.go#L192)
if the key isn't found. (I assume that it is not intentional to restrict
this to a generic error.) This means that the gRPC interface must search
the error string for "not found", which is unreliable. We would prefer
to use `keyerror.IsErrKeyNotFound`. Furthermore, `GetByNameOrAddress`
[can return an error from
either](https://github.com/gnolang/gno/blob/199cd29584d44812a0aec3606bbff37a320c609a/tm2/pkg/crypto/keys/keybase.go#L175-L177)
`GetByName` or `GetByAddress`. It is preferable to return just one error
type for key not found.

This pull request updates `GetByAddress` to use
`keyerror.NewErrKeyNotFound` with the same error message.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated
graphs](https://gnoland.github.io/benchmarks), if any. More info
[here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>

Signed-off-by: Jeff Thompson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Status: Done
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants