Skip to content

Improve error.type classification for wrapped error.suggestion failures#7140

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-error-type-categorization
Draft

Improve error.type classification for wrapped error.suggestion failures#7140
Copilot wants to merge 5 commits intomainfrom
copilot/fix-error-type-categorization

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Closes #7139

Builds on #7051

Context

MapError classifies ErrorWithSuggestion early, setting ResultCode=error.suggestion — but the derived error.type attribute was just the raw Go type from errorType(). In practice this meant ARM deployment failures wrapped with suggestions showed up as *azapi.DeploymentErrorLine instead of service.arm.deployment.failed, making the telemetry much less useful.

Summary

This PR introduces classifySuggestionType() to recognize structured inner errors before falling back to errorType(). It reuses the same telemetry categories as MapError — ARM responses (service.arm.<status>), ARM deployments (service.arm.<op>.failed), extension service/local errors, tool execution errors, auth failures, network errors, and sentinels — so error.type is always a meaningful code rather than an opaque Go type name.

The sentinel errors.Is() checks are consolidated into a shared classifySentinel() function to avoid duplication between MapError and classifySuggestionType. Both functions check structured types before sentinels, ensuring they always agree on the classification for a given error. A new Test_ClassifySuggestionType_MatchesMapError test exercises every error category through both paths and asserts they produce identical codes.

Original prompt

This section details on the original issue you should resolve

<issue_title>Improve error.type categorization when ResultCode is error.suggestion</issue_title>
<issue_description>In our telemetry when ResultCode is error.suggestion, we're seeing a bunch of events where error.type is simply azapi.DeploymentErrorLine and doesn't seem intended.


Initial analysis by agent

It's a consequence of the errors.As match ordering in MapError. Here's the root cause:

The errWithSuggestion check comes before armDeployErr (line ~69 vs ~95). When an AzureDeploymentError is wrapped inside an ErrorWithSuggestion, the suggestion branch wins:

ErrorWithSuggestion
  └── Err: *AzureDeploymentError
              └── Unwrap() → [Inner, Details (*DeploymentErrorLine)]

The error.suggestion branch then calls errorType(inner) on the unwrapped inner error. Since AzureDeploymentError implements Unwrap() []error (returning [Inner, Details]), errorType resolves to the leaf types — *azapi.DeploymentErrorLine — via reflect.TypeOf().

What's lost: All the rich ARM deployment telemetry (error codes, operation type, the service.arm.*.failed classification) is completely bypassed. Instead you just get:

  • ResultCode = error.suggestion
  • error.type = *azapi.DeploymentErrorLine (a raw Go type name, not useful)

The chain:

  1. errors.As(err, &errWithSuggestion) matches first → errCode = "error.suggestion"
  2. classifySentinel(inner) returns "" (ARM errors aren't sentinels)
  3. errorType(inner) unwraps AzureDeploymentError → multi-unwrap reaches *DeploymentErrorLine

To fix: The errWithSuggestion branch should attempt to classify the inner error against structured error types (like armDeployErr, respErr, etc.) before falling back to errorType.</issue_description>

<agent_instructions>Can you conduct a separate thorough investigation to see if it aligns with initial analysis, then implement the fix/improvements?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 2 commits March 13, 2026 22:22
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error.type categorization for error.suggestion Improve error.type classification for wrapped error.suggestion failures Mar 13, 2026
Copilot AI requested a review from JeffreyCA March 13, 2026 22:27
@JeffreyCA
Copy link
Contributor

@copilot is there any way we could reduce some of the duplication as a result of this change?

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 13, 2026

@copilot is there any way we could reduce some of the duplication as a result of this change?

Consolidated all sentinel errors.Is checks into classifySentinel, which was already the shared entry point for both MapError and classifySuggestionType. This replaces MapError's 12-line sentinel if/else chain with a single classifySentinel(err) call and removes ~44 lines of duplicate sentinel checks from classifySuggestionType. Net reduction of 47 lines (21 insertions, 68 deletions) in 06d0ddf9.

The remaining typed error code computations in classifySuggestionType (ResponseError, AzureDeploymentError, ServiceError, etc.) are code-only variants of the MapError logic—they compute just the error code string without the full detail/attribute emission that MapError needs. Extracting those further would add indirection without meaningful dedup since the shared part is typically a single fmt.Sprintf line.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JeffreyCA
Copy link
Contributor

/azp run azure-dev - cli

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

Improve error.type categorization when ResultCode is error.suggestion

2 participants