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(errors): support error checking methods for new problem structures #212

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

dpopp07
Copy link
Member

@dpopp07 dpopp07 commented Mar 19, 2024

Adds previously returned errors to the "Unwrap" chain for checking against in methods like "errors.Is()" and adds an implementation of "Is" to Problem types to enable equality checking against problems.

Also, adds all of the previously returned errors back into the problem structures to maintain full compatibility with downstream code.

Adds previously returned errors to the "Unwrap" chain for checking against
in methods like "errors.Is()" and adds an implementation of "Is" to Problem
types to enable equality checking against problems.

Also, adds all of the previously returned errors back into the problem
structures to maintain full compatibility with downstream code.

Signed-off-by: Dustin Popp <[email protected]>
@dpopp07 dpopp07 requested review from pyrooka and padamstx March 19, 2024 19:30
}
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo())
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo())
Copy link
Member Author

Choose a reason for hiding this comment

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

@pyrooka Norbert - I want to publicly acknowledge that "you told me so" with respect to saving the previously returned errors in case we ever needed them! 😂

Turns out, we do need them - so this PR is adding everything back in just like you recommended in my last PR 😛

Copy link
Member

Choose a reason for hiding this comment

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

Some developers never learn... 😂

Copy link
Member

Choose a reason for hiding this comment

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

Haha, thanks for mentioning me, appreciate it! But I hope you didn't do this to protect yourself from future complications that might come up, so you can point at me and say "Hey, that was Norbert's idea, not mine..." 😂

@@ -109,12 +116,21 @@ func (e *IBMProblem) GetCausedBy() Problem {
// it does not include the error instance the method is called on - that is
// looked at separately by the "errors" package in functions like "As".
func (e *IBMProblem) Unwrap() []error {
var errs []error
Copy link
Member Author

Choose a reason for hiding this comment

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

The changes to this method are the key component of this PR. These changes re-enable compatibility with methods like errors.Is by including the previously returned errors in the list of "unwrapped" errors.

The changes to add Is implementations to the problem types are purely extra - they allow for comparisons against problems that go beyond being the same instance. They enable equality for the same problem scenario (i.e. same ID) which is what the new types are all about.

Copy link
Member

@padamstx padamstx left a comment

Choose a reason for hiding this comment

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

Looks great!

}
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo())
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo())
Copy link
Member

Choose a reason for hiding this comment

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

Some developers never learn... 😂

Copy link
Member

@pyrooka pyrooka left a comment

Choose a reason for hiding this comment

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

Looks good!

}
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo())
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo())
Copy link
Member

Choose a reason for hiding this comment

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

Haha, thanks for mentioning me, appreciate it! But I hope you didn't do this to protect yourself from future complications that might come up, so you can point at me and say "Hey, that was Norbert's idea, not mine..." 😂

@dpopp07 dpopp07 merged commit 65eb01d into main Mar 20, 2024
4 checks passed
@dpopp07 dpopp07 deleted the dp/error-is-method branch March 20, 2024 14:31
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 5.16.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

ibm-devx-sdk pushed a commit that referenced this pull request Mar 20, 2024
## [5.16.2](v5.16.1...v5.16.2) (2024-03-20)

### Bug Fixes

* **errors:** support error checking methods for new problem structures ([#212](#212)) ([65eb01d](65eb01d))
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