Skip to content

fix(Resources): propagate ARM nested error details in deployment validation#29445

Merged
VeryEarly merged 2 commits into
Azure:mainfrom
jeffreybulanadi:fix/issue-28308-deployment-validation-error-details
Apr 28, 2026
Merged

fix(Resources): propagate ARM nested error details in deployment validation#29445
VeryEarly merged 2 commits into
Azure:mainfrom
jeffreybulanadi:fix/issue-28308-deployment-validation-error-details

Conversation

@jeffreybulanadi

Copy link
Copy Markdown
Contributor

Description

Fixes #28308

When New-AzDeployment fails validation with MultipleErrorsOccurred, the actual inner error details (e.g. KeyVaultParameterReferenceSecretRetrieveFailed) were silently dropped. The HandleError method was using ex.InnerException (the .NET exception chain) as the ARM Details payload instead of cloudEx.Body.Details, which holds the true ARM sub-errors from the HTTP response body.

Root Cause

In NewResourceManagerSdkClient.HandleError(Exception ex), when a CloudException is caught, the original code called HandleError(ex.InnerException) to populate the Details field. However, CloudException.InnerException is a low-level HTTP exception, not the ARM nested errors. The ARM nested errors live in cloudEx.Body.Details and were never mapped, so DisplayInnerDetailErrorMessage was never reached.

Changes

  • Rewrote HandleError to use pattern matching for CloudException and map cloudEx.Body?.Details through a new ConvertCloudErrorToErrorResponse helper
  • Added private static ConvertCloudErrorToErrorResponse that recursively converts IList<CloudError> to IList<ErrorResponse>, preserving the full nested hierarchy
  • Added regression test ValidateDeployment_WhenCloudExceptionHasNestedDetails_PropagatesInnerErrors
  • Updated ChangeLog.md under Upcoming Release

Before vs After

Before: Only the top-level vague error was shown:

New-AzDeployment: MultipleErrorsOccurred

After: All nested errors are surfaced:

New-AzDeployment: MultipleErrorsOccurred
  KeyVaultParameterReferenceSecretRetrieveFailed: Secret 'mySecret1' in Key Vault '...' could not be found
  KeyVaultParameterReferenceSecretRetrieveFailed: Secret 'mySecret2' in Key Vault '...' could not be found

Testing

dotnet test src\Resources\Resources.Test\Resources.Test.csproj --filter "ValidateDeployment_WhenCloudExceptionHasNestedDetails_PropagatesInnerErrors"

All 15 ResourceClientTests pass with 0 regressions.

Checklist

  • Follows Microsoft patterns and naming conventions
  • Unit test added for the regression case
  • Build succeeds with 0 errors and 0 warnings
  • ChangeLog.md updated

…dation

When New-AzDeployment fails validation with MultipleErrorsOccurred, the
actual inner error details (e.g. KeyVaultParameterReferenceSecretRetrieveFailed)
were silently dropped. HandleError was using ex.InnerException (the .NET
exception chain) as the ARM Details payload, instead of cloudEx.Body.Details
which holds the true ARM sub-errors from the HTTP response body.

Changes:
- Rewrote HandleError to use pattern matching for CloudException and
  map cloudEx.Body?.Details via new ConvertCloudErrorToErrorResponse helper
- Added private static ConvertCloudErrorToErrorResponse that recursively
  converts IList<CloudError> to IList<ErrorResponse>
- Added regression test ValidateDeployment_WhenCloudExceptionHasNestedDetails_PropagatesInnerErrors

Fixes Azure#28308

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 23, 2026 10:27
@azure-client-tools-bot-prd

Copy link
Copy Markdown
Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution @jeffreybulanadi! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes New-AzDeployment validation error handling in the Resources module so ARM nested error details from deployment validation responses are preserved and surfaced to users (addressing #28308).

Changes:

  • Updated NewResourceManagerSdkClient.HandleError to map ARM nested errors from CloudException.Body.Details via a recursive converter.
  • Added a regression unit test covering MultipleErrorsOccurred with nested details.
  • Added an Upcoming Release entry in src/Resources/Resources/ChangeLog.md.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Resources/ResourceManager/SdkClient/NewResourceManagerSdkClient.cs Converts CloudException.Body.Details into ErrorResponse.Details to preserve nested ARM errors during deployment validation.
src/Resources/Resources.Test/Models.ResourceGroups/ResourceClientTests.cs Adds a regression test ensuring nested ARM validation errors are propagated into TemplateValidationInfo.
src/Resources/Resources/ChangeLog.md Documents the user-visible fix for nested ARM validation errors not being shown.

Comment thread src/Resources/ResourceManager/SdkClient/NewResourceManagerSdkClient.cs Outdated
Comment thread src/Resources/Resources/ChangeLog.md Outdated
- Add fallback to cloudEx.Message when CloudException body has no message
- Add fallback to HandleError(ex.InnerException) when ARM body has no details,
  so CloudException cases without a deserialized ARM body remain actionable
- Expand ARM acronym in ChangeLog to 'ARM (Azure Resource Manager)' on first use

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@VeryEarly VeryEarly self-assigned this Apr 24, 2026
@VeryEarly

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Contributor
Azure Pipelines successfully started running 3 pipeline(s).

@VeryEarly VeryEarly merged commit 9e0c3eb into Azure:main Apr 28, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New-AzDeployment not reporting properly the bicep deployment error

3 participants