-
Notifications
You must be signed in to change notification settings - Fork 114
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
Implemented support for checkable errors #131
Conversation
Personally, I'm not a fan of exporting custom error types. What's the use case for needing to determine whether or not an error was generated by this package? As it's written today, any error returned by any function/method is, by definition, generated by this package since all of them are constructed directly. There's no need for anyone to use |
Well... I had a need for it and saw that no one had done anything to fix the bug that was reported 4 years ago. In my experience most packages (at least the ones I use) export errors I can check against with errors.Is(). I'm not exactly sure what you mean by "any error returned by any function/method is, by definition, generated by this package since all of them are constructed directly"? |
I see. Your code is not parsing/decoding the UUID values directly but you want to be able to detect that the error returned by gRPC came from If that's the case, I would personally define a couple of sentinel errors and refactor those
Consumers could still use |
Sure, declaring pre-allocated errors like in your example would have been great! I can refactor my code a bit and try to simplify it a bit. |
Thinking out loud ... we could probably use the "constant" sentinel errors and keep the current error strings with careful applications of Assuming
|
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.
LGTM. Thanks for the submission and for working with me to resolve the feedback.
Hi @PatrLind , I'm finally getting some time to take a look at the open PRs. I decided to merge in the updated RFC one because it seemed like it'd have the least disruption if I merged it in first. Apologies if this generates conflicts. Also, codecov hasnt been running for a bit so the next time a change is made to this review it may come up with some missing coverage. I'll only ask for test coverage on areas you introduced. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #131 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 5 +1
Lines 513 447 -66
=========================================
- Hits 513 447 -66 ☔ View full report in Codecov by Sentry. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/gofrs/uuid/v5](https://togithub.com/gofrs/uuid) | `v5.1.0` -> `v5.2.0` | [![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgofrs%2fuuid%2fv5/v5.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fgofrs%2fuuid%2fv5/v5.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fgofrs%2fuuid%2fv5/v5.1.0/v5.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgofrs%2fuuid%2fv5/v5.1.0/v5.2.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>gofrs/uuid (github.com/gofrs/uuid/v5)</summary> ### [`v5.2.0`](https://togithub.com/gofrs/uuid/releases/tag/v5.2.0) [Compare Source](https://togithub.com/gofrs/uuid/compare/v5.1.0...v5.2.0) This minor release updates the UUID v6 and v7 features of package to be complaint to draft RFC-9562, which replaces the previous family of uuid drafts. Additionally, it adds more specific error types, and tunes up Github Actions safety practices #### What's Changed - Update to RFC 9562 by [@​kohenkatz](https://togithub.com/kohenkatz) in [https://github.com/gofrs/uuid/pull/117](https://togithub.com/gofrs/uuid/pull/117) - \[StepSecurity] Apply security best practices by [@​step-security-bot](https://togithub.com/step-security-bot) in [https://github.com/gofrs/uuid/pull/135](https://togithub.com/gofrs/uuid/pull/135) - Bump actions/checkout from 2.7.0 to 4.1.5 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gofrs/uuid/pull/137](https://togithub.com/gofrs/uuid/pull/137) - Bump ossf/scorecard-action from 2.0.6 to 2.3.3 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gofrs/uuid/pull/136](https://togithub.com/gofrs/uuid/pull/136) - Bump actions/dependency-review-action from 2.5.1 to 4.3.2 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gofrs/uuid/pull/138](https://togithub.com/gofrs/uuid/pull/138) - Bump actions/upload-artifact from 3.1.3 to 4.3.3 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gofrs/uuid/pull/140](https://togithub.com/gofrs/uuid/pull/140) - Bump codecov/codecov-action from 2.1.0 to 4.3.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/gofrs/uuid/pull/139](https://togithub.com/gofrs/uuid/pull/139) - Implemented support for checkable errors by [@​PatrLind](https://togithub.com/PatrLind) in [https://github.com/gofrs/uuid/pull/131](https://togithub.com/gofrs/uuid/pull/131) #### New Contributors - [@​kohenkatz](https://togithub.com/kohenkatz) made their first contribution in [https://github.com/gofrs/uuid/pull/117](https://togithub.com/gofrs/uuid/pull/117) - [@​step-security-bot](https://togithub.com/step-security-bot) made their first contribution in [https://github.com/gofrs/uuid/pull/135](https://togithub.com/gofrs/uuid/pull/135) - [@​dependabot](https://togithub.com/dependabot) made their first contribution in [https://github.com/gofrs/uuid/pull/137](https://togithub.com/gofrs/uuid/pull/137) - [@​PatrLind](https://togithub.com/PatrLind) made their first contribution in [https://github.com/gofrs/uuid/pull/131](https://togithub.com/gofrs/uuid/pull/131) **Full Changelog**: gofrs/uuid@v5.1.0...v5.2.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 6am on Monday" in timezone Europe/Paris, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/cozy/cozy-stack). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNTEuMiIsInVwZGF0ZWRJblZlciI6IjM3LjM1MS4yIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->
This is a possible fix for issue #86.
I have added two custom error types that can be used to check if an error is coming from the uuid package.
Not sure if the package maintainers agree with my implementation, but feel free to tell me if it is suitable or not.
Also not sure if there needs to be two errors types. Perhaps one is good enough?
No error messages should be different from before.
err.Error()
should return the same string.It should now also be possible to check for uuid errors by using the
errors.Is()
anderrors.As()
functions.I added a test function to verify that the implementation is OK.