-
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
feat(orm)!: return ormerrors.NotFound for Get methods in codegen #11113
Conversation
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.
error here makes sense. Seems easier to handle too
Codecov Report
@@ Coverage Diff @@
## master #11113 +/- ##
==========================================
+ Coverage 65.77% 65.93% +0.16%
==========================================
Files 649 698 +49
Lines 66602 70810 +4208
==========================================
+ Hits 43805 46692 +2887
- Misses 20280 21253 +973
- Partials 2517 2865 +348
|
What if we returned grpc status NotFound? That would be most convenient in query servers. We could make our errors module compatible with grpc codes possibly |
Added a helper |
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.
🙏🏻 thanks!
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.
Added a helper
ormerrors.IsNotFound()
in case we want to change things later... I do think there's value in considering grpc errors here
+1, I've been advocating a lot for sdkerrors to implement GRPCStatus()
.
+1 also for returning errors rather than a boolean.
I think in the end orm errors can be of three categories (when you're interacting with it):
- NotFound for Delete/Update/List/Read (grpcstatus.NotFound)
- AlreadyExists for Create (grpcstatus.AlreadyExists)
- BadRequest for everything bad in the request format (invalid type, invalid indexes query, etc) (grpcstatus.InvalidArgument)
Is GRPCStatus() part of the public API? Seems like an implementation detail I'm not sure is safe to depend on |
It is not part of the public API... We could have only sdk/error implement it. So if the |
errors.NewWithCode(codespace, 1, code.NotFound, "not found") We can either do that or use grpc status directly. What do you think? |
## Description Follow-up to #11113 (review). This PR also makes `New` an alias of `Register` as some packages are using `New` as if it were `Register` but are not actually registering their error codes. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Description
I was talking with @technicallyty and we agreed that returning an error value when an entity is not found is the common golang idiom. What do you think @fdymylja ?
You can see how this looks in practice in
module_test.go
. I'm not actually sure this makes the code more succinct or the orm any easier to use. But maybe in certain cases yes.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change