Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 6, 2026

Description

azd auth token writes JSON to stderr on failure: {"type":"consoleMessage","data":{"message":"ERROR: ..."}}. Currently this JSON appears verbatim in exceptions, producing noisy output.

Changes

  • Added JSON parsing (ProcessCliErrorForDisplay): Extracts .data.message from azd JSON output, trims whitespace, falls back to raw text on parse failure or empty content
  • Removed special-case substitution: Previously checked for "azd auth login" in errors and substituted with a custom constant. Now uses azd's messages directly since they're already user-friendly
  • Test coverage: 7 new tests for JSON parsing (valid JSON, malformed JSON, missing fields, whitespace handling, empty messages, fallback scenarios)

Before/After

Before:

AzureDeveloperCliCredential authentication failed: {"type":"consoleMessage","timestamp":"2024-01-01T00:00:00Z","data":{"message":"\nERROR: fetching token: interactive login required"}}

After:

AzureDeveloperCliCredential authentication failed: ERROR: fetching token: interactive login required

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.
Original prompt

This section details on the original issue you should resolve

<issue_title>Improve AzureDeveloperCliCredential error messages by parsing azd output</issue_title>
<issue_description>When azd auth token fails, it writes JSON to stderr:

{"type":"consoleMessage","timestamp":"...","data":{"message":"\nERROR: fetching token: ..."}}

Today AzureDeveloperCliCredential includes this raw JSON verbatim in error messages, producing noisy output like:

AzureDeveloperCliCredential authentication failed: {"type":"consoleMessage","timestamp":"...","data":{"message":"\nERROR: fetching token: ..."}}

We should instead parse this JSON's .data.message field to produce cleaner errors like:

AzureDeveloperCliCredential authentication failed: ERROR: fetching token: ...

Note .data.message may contain leading/trailing whitespace that should be trimmed.

This also lets us remove special-case error handling (e.g., substituting another message when azd's contains "azd auth login") because the parsed messages from azd are already user-friendly.

When JSON parsing fails or .data.message isn't set or has an empty value, include the raw text as before.</issue_description>

<agent_instructions>This issue is for the Azure.Identity library, which you can find under sdk/identity/</agent_instructions>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 6, 2026 03:08
Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
…irectly

Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
…agement

Co-authored-by: JonathanCrd <17486462+JonathanCrd@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve AzureDeveloperCliCredential error messages by parsing azd output Parse JSON output from azd CLI for cleaner error messages Feb 6, 2026
Copilot AI requested a review from JonathanCrd February 6, 2026 03:15
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 AzureDeveloperCliCredential error messages by parsing azd output

2 participants