-
Notifications
You must be signed in to change notification settings - Fork 44
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(error): handle wrapped errors in IsError() #374
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`hcloud.IsError()` currently does a type assertion to get our error type. This breaks if the error was previously wrapped, causing it to always return "false". This happens often if the error is passed through multiple functions before error handling is being done. Example of code that is currently broken: ```go // Error returned by hcloud-go err := hcloud.Error{ Code: hcloud.ErrorCodeUnauthorized } // Error gets wrapped at some point in the call-chain err = fmt.Errorf("failed to foobar: %w", err) // Now the error is not properly identified hcloud.IsError(err, hcloud.ErrorCodeUnauthorized) // false ```
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #374 +/- ##
==========================================
+ Coverage 76.42% 76.49% +0.07%
==========================================
Files 32 32
Lines 6732 6727 -5
==========================================
+ Hits 5145 5146 +1
+ Misses 1179 1174 -5
+ Partials 408 407 -1 ☔ View full report in Codecov by Sentry. |
jooola
approved these changes
Jan 12, 2024
apricote
added
the
backport release-1.x
Open PR against release-1.x with these changes after the PR is merged.
label
Jan 15, 2024
github-actions bot
pushed a commit
that referenced
this pull request
Jan 15, 2024
`hcloud.IsError()` currently does a type assertion to get our error type. This breaks if the error was previously wrapped, causing it to always return "false". This happens often if the error is passed through multiple functions before error handling is being done. Example of code that is currently broken: ```go // Error returned by hcloud-go err := hcloud.Error{ Code: hcloud.ErrorCodeUnauthorized } // Error gets wrapped at some point in the call-chain err = fmt.Errorf("failed to foobar: %w", err) // Now the error is not properly identified hcloud.IsError(err, hcloud.ErrorCodeUnauthorized) // false ``` (cherry picked from commit 83df108)
This was referenced Jan 15, 2024
apricote
added a commit
that referenced
this pull request
Jan 15, 2024
`hcloud.IsError()` currently does a type assertion to get our error type. This breaks if the error was previously wrapped, causing it to always return "false". This happens often if the error is passed through multiple functions before error handling is being done. Example of code that is currently broken: ```go // Error returned by hcloud-go err := hcloud.Error{ Code: hcloud.ErrorCodeUnauthorized } // Error gets wrapped at some point in the call-chain err = fmt.Errorf("failed to foobar: %w", err) // Now the error is not properly identified hcloud.IsError(err, hcloud.ErrorCodeUnauthorized) // false ``` --- Backport 83df108 from #374. Co-authored-by: Julian Tölle <julian.toelle@hetzner-cloud.de>
apricote
pushed a commit
that referenced
this pull request
Mar 27, 2024
🤖 I have created a release *beep* *boop* --- ## [2.7.0](v2.6.0...v2.7.0) (2024-03-27) ### Features * add volume format property ([#397](#397)) ([c0940af](c0940af)) * **error:** handle wrapped errors in IsError() ([#374](#374)) ([83df108](83df108)) * require Go >= 1.20 ([#392](#392)) ([299f181](299f181)) * **server:** deprecate ServerRescueTypeLinux32 ([#378](#378)) ([2f334c3](2f334c3)) * test with Go 1.22 ([#391](#391)) ([49be506](49be506)) ### Bug Fixes * falsely omitted fields in firewall schema ([#396](#396)) ([a3509b6](a3509b6)) * LoadBalancerUpdateServiceOpts not converted correctly ([#394](#394)) ([0f187ce](0f187ce)) * primary ip assignee id not mapped to nil ([#395](#395)) ([b5fea38](b5fea38)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
apricote
pushed a commit
to hetznercloud/fleeting-plugin-hetzner
that referenced
this pull request
Sep 12, 2024
…etznercloud/fleeting-plugin-hetzner!38) This MR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/hetznercloud/hcloud-go/v2](https://github.com/hetznercloud/hcloud-go) | require | minor | `v2.6.0` -> `v2.7.2` | --- ### Release Notes <details> <summary>hetznercloud/hcloud-go (github.com/hetznercloud/hcloud-go/v2)</summary> ### [`v2.7.2`](https://github.com/hetznercloud/hcloud-go/releases/tag/v2.7.2) [Compare Source](hetznercloud/hcloud-go@v2.7.1...v2.7.2) ##### Bug Fixes - creating firewall with rules not working correctly ([#​412](hetznercloud/hcloud-go#412)) ([43b2bab](hetznercloud/hcloud-go@43b2bab)) ### [`v2.7.1`](https://github.com/hetznercloud/hcloud-go/releases/tag/v2.7.1) [Compare Source](hetznercloud/hcloud-go@v2.7.0...v2.7.1) ##### Bug Fixes - setting firewall rules not working correctly ([#​405](hetznercloud/hcloud-go#405)) ([16daea0](hetznercloud/hcloud-go@16daea0)) ### [`v2.7.0`](https://github.com/hetznercloud/hcloud-go/releases/tag/v2.7.0) [Compare Source](hetznercloud/hcloud-go@v2.6.0...v2.7.0) ##### Features - add volume format property ([#​397](hetznercloud/hcloud-go#397)) ([c0940af](hetznercloud/hcloud-go@c0940af)) - **error:** handle wrapped errors in IsError() ([#​374](hetznercloud/hcloud-go#374)) ([83df108](hetznercloud/hcloud-go@83df108)) - require Go >= 1.20 ([#​392](hetznercloud/hcloud-go#392)) ([299f181](hetznercloud/hcloud-go@299f181)) - **server:** deprecate ServerRescueTypeLinux32 ([#​378](hetznercloud/hcloud-go#378)) ([2f334c3](hetznercloud/hcloud-go@2f334c3)) - test with Go 1.22 ([#​391](hetznercloud/hcloud-go#391)) ([49be506](hetznercloud/hcloud-go@49be506)) ##### Bug Fixes - falsely omitted fields in firewall schema ([#​396](hetznercloud/hcloud-go#396)) ([a3509b6](hetznercloud/hcloud-go@a3509b6)) - LoadBalancerUpdateServiceOpts not converted correctly ([#​394](hetznercloud/hcloud-go#394)) ([0f187ce](hetznercloud/hcloud-go@0f187ce)) - primary ip assignee id not mapped to nil ([#​395](hetznercloud/hcloud-go#395)) ([b5fea38](hetznercloud/hcloud-go@b5fea38)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zMjQuMSIsInVwZGF0ZWRJblZlciI6IjM3LjMyNC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backport release-1.x
Open PR against release-1.x with these changes after the PR is merged.
Improvement
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hcloud.IsError()
currently does a type assertion to get our error type. This breaks if the error was previously wrapped, causing it to always return "false". This happens often if the error is passed through multiple functions before error handling is being done.Example of code that is currently broken: