Skip to content

SDK: Adding fault details handling for wrapped faults - #4144

Open
bhagatp10 wants to merge 1 commit into
vmware:mainfrom
bhagatp10:wrapped_fault_details
Open

bhagatp10 wants to merge 1 commit into
vmware:mainfrom
bhagatp10:wrapped_fault_details

Conversation

@bhagatp10

@bhagatp10 bhagatp10 commented Oct 7, 2026 •

Copy link
Copy Markdown

Description

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 #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:

  1. vim25/soap/error.go:
  • IsSoapFault and IsVimFault use errors.As.
  • ToSoapFault and ToVimFault use errors.As and return nil if the chain has no fault. They no longer panic.
  • Doc comments added to the four helpers.
  1. vim25/soap/error_test.go:
  • New TestWrappedFaults. It covers a soap fault and a vim fault, each wrapped with %w, and checks that Is* returns true and To* returns the original fault. It also covers a plain, unwrapped error, where Is* returns false and To* returns nil.

Closes: The change is an enhancement to the fix for the issue #2519

How Has This Been Tested?

  • go test ./vim25/soap/ passes, including the new TestWrappedFaults.
  • go test ./property/ ./vim25/mo/ ./eam/... passes. These packages use the changed helpers.
  • go test ./simulator/ passes with -run 'Fault|Wait|Retrieve|Error|Search|ResourcePool'. I ran only this subset, not the full suite.
  • go vet ./vim25/soap/ and gofmt are clean.

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>
@bhagatp10 bhagatp10 changed the title Adding fault details handling for wrapped faults SDK: Adding fault details handling for wrapped faults Oct 7, 2026

@atanaskrastilov atanaskrastilov left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM! Seem like a correct use of errors.As for unwrapping the errors and checking against the correct type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants