Repository navigation
Conversation
soap.IsSoapFault, soap.ToSoapFault, soap.IsVimFault and soap.ToVimFault used plain type assertions on the error. They therefore only worked on the exact error value returned by the soap client. If a caller wrapped the error (fmt.Errorf("...: %w", err)), the helpers stopped recognizing it:
IsSoapFault and IsVimFault returned false.
ToSoapFault and ToVimFault panicked with a failed type assertion.
This changes the four helpers to use errors.As, so they find the fault anywhere in the error chain.
Related to vmware#2519. The requester there can't get at fault.Detail.Fault, and the unexported soapFaultError was the stated reason. The detail has been reachable through ToSoapFault(err).Detail.Fault and the fault package. Wrapped errors, which are common in real callers, lost that access. This PR closes that gap.
Signed-off-by: Prajwal Bhagat <prajwal.bhagat@broadcom.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
atanaskrastilov
left a comment
There was a problem hiding this comment.
LGTM! Seem like a correct use of errors.As for unwrapping the errors and checking against the correct type.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
soap.IsSoapFault,soap.ToSoapFault,soap.IsVimFaultandsoap.ToVimFaultused plain type assertions on the error. They therefore only worked on the exact error value returned by the soap client. If a caller wrapped the error (fmt.Errorf("...: %w", err)), the helpers stopped recognizing it:This changes the four helpers to use errors.As, so they find the fault anywhere in the error chain.
Related to #2519. The requester there can't get at fault.Detail.Fault, and the unexported soapFaultError was the stated reason. The detail has been reachable through ToSoapFault(err).Detail.Fault and the fault package. Wrapped errors, which are common in real callers, lost that access. This PR closes that gap.
Changes:
Closes: The change is an enhancement to the fix for the issue #2519
How Has This Been Tested?