Skip to content

Conversation

@anannya03
Copy link
Member

@anannya03 anannya03 commented Feb 11, 2026

Description

azd auth token writes JSON to stderr on failure:

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

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

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

This PR uses the existing extractUserFriendlyErrorFromAzdOutput() method to output data.message to the users.

The issue description also mentioned that we'd want to show raw output on failure, hence when data.message or message is null, we return the raw output to the user. Lastly, with this change we want to remove any 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.

Fixes #47920

Azd logged in but wrong scope-

Screenshot 2026-02-10 153445

Azd logged out

Screenshot 2026-02-10 153540

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves AzureDeveloperCliCredential error messaging by parsing Azure Developer CLI (azd auth token) JSON error output and surfacing the user-friendly .data.message field (falling back to raw output when no message is available).

Changes:

  • Updated Azure Developer CLI failure handling to use extractUserFriendlyErrorFromAzdOutput(...) for exceptions instead of emitting raw JSON/special-cased messages.
  • Adjusted extractUserFriendlyErrorFromAzdOutput(...) behavior to return raw output when no valid messages are found (and treat whitespace-only output as empty).
  • Updated unit tests and changelog entry to reflect the new behavior.

Reviewed changes

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

File Description
sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientBase.java Routes azd failure output through the existing azd JSON message extractor; tweaks extractor empty/no-message behavior.
sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java Updates test to expect raw output when no extractable message exists.
sdk/identity/azure-identity/CHANGELOG.md Adds an unreleased changelog entry describing the improved azd error handling.

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

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

Improve AzureDeveloperCliCredential error messages by parsing azd output

1 participant