-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
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]>
} | ||
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo()) | ||
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo()) |
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.
@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 😛
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.
Some developers never learn... 😂
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.
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 |
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.
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.
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.
Looks great!
} | ||
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo()) | ||
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo()) |
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.
Some developers never learn... 😂
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.
Looks good!
} | ||
err = SDKErrorf(nil, errMsg, "no-connection-made", getComponentInfo()) | ||
err = SDKErrorf(err, "", "no-connection-made", getComponentInfo()) |
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.
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..." 😂
🎉 This PR is included in version 5.16.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
## [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))
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.