Skip to content

Improve AzureDeveloperCliCredential error messages by parsing azd output #45049

@chlowell

Description

@chlowell

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.

Metadata

Metadata

Assignees

Projects

Status

Untriaged

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions