PowerShell: preserve structured ARM failure details in `ErrorRecord`

未关闭
#1,065 4 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@VeryEarly 已经在做这个了。

开始于 2026年10月22日。

评估

这个 Issue 还没有评估数据。

描述

act-codegen-extensibility-squad X Engineering Agent Triaged
Summary

In the Az 0.1.4 preview bundle, Get-AzResourceGroup reports an ARM 404 through a generic System.Exception, with category NotSpecified and no populated ErrorDetails or TargetObject.

The HTTP status and ARM error code survive in the message text, but callers must parse that text to distinguish service failures reliably.

Reproduction

Using an authenticated profile and a resource-group name that does not exist:

try {
    Get-AzResourceGroup `
        -SubscriptionId '<subscription-id>' `
        -Name 'azclips-ro-check-does-not-exist' `
        -ErrorAction Stop
} catch {
    [pscustomobject]@{
        ExceptionType = $_.Exception.GetType().FullName
        ErrorId       = $_.FullyQualifiedErrorId
        Category      = $_.CategoryInfo.Category
        ErrorDetails  = $_.ErrorDetails
        TargetObject  = $_.TargetObject
        Message       = $_.Exception.Message
    } | Format-List
}
Observed result
Field Observed value
Exception type System.Exception
Error ID ResourceGroupError,Microsoft.Azure.Azclips.Cmdlets.Resources.GetResourceGroupCmdlet
Category NotSpecified
ErrorDetails Null
TargetObject Null
Message HTTP 404, request URL, and embedded ARM JSON containing ResourceGroupNotFound

-ErrorAction Stop and catch work. The concern is the information available inside the caught record, not whether the error is catchable.

As a control, an unknown cmdlet parameter retains a native ParameterBindingException, category InvalidArgument, and the specific NamedParameterNotFound error ID.

Relevant implementation

The released CmdletOutputStreamsFactory constructs an ErrorRecord using:

new Exception(value?.ToString() ?? string.Empty)

and a null target. This matches the observed generic exception and missing target.

Suggested improvement

Preserve the service failure information in a documented, programmatically accessible form:

  • HTTP status and ARM error code.
  • A meaningful error category—for example, ObjectNotFound for this case.
  • The requested resource as TargetObject.
  • An underlying exception or structured payload that retains useful service details.

Keep the human-readable message and existing -ErrorAction behavior. The goal is to let scripts handle a missing resource without matching strings inside a message.

Environment and scope
  • Release: v0.1.4.20260930T053744Z
  • Az rollup 0.1.4; Az.Resources 0.1.2
  • PowerShell 7.6.4 on Debian 13
  • Read-only request; no resources created or modified
  • One ARM 404 case tested; other service-error categories were not tested
主要语言
C#
星标
18
派生
10
平均合并
1 天 20 小时
30 天内合并 PR
157

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Azure/azclips 的其他 Issue

查看 Azure/azclips 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。