Azure / Azure/azure-dev

Fix `AzureDeveloperCLICredential` error message parsing for newer azd versions in Azure SDKs

Open
#7,728 0 comments 0 reactions 1 assignee Claimed by @JeffreyCA View on GitHub
area/auth area/error-handling bug
Dominant language
Go
Stars
569
Forks
364
Avg merge
2d 19h
Merged PRs (30d)
136

Description

The azd auth error parsing improvements to `azidentity` in https://github.com/Azure/azure-sdk-for-go/pull/25984 only support the older `consoleMessage` style JSON responses from `azd auth token --output json`:

```
{"type":"consoleMessage","timestamp":"2026-04-14T22:26:31.711362638Z","data":{"message":"\nERROR: fetching token: failed to authenticate:\n(invalid_tenant) AADSTS90002: Tenant 'test' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 7ea0f1dd-62d9-48ec-8129-241fb0550e00 Correlation ID: 33cd3369-ca90-4981-9e34-e85bac353b91 Timestamp: 2026-04-14 22:26:31Z\n\n"}}
```

Since [v1.23.7](https://github.com/Azure/azure-dev/releases/tag/azure-dev-cli_1.23.7) (specifically from PR https://github.com/Azure/azure-dev/pull/6827), the error JSON response format has changed:

```
> azd auth token -ojson --tenant-id test
{"type":"consoleMessage","timestamp":"2026-04-13T17:43:24.7558297-07:00","data":{"message":"\n"}}
{"error":"fetching token: failed to authenticate:\n(invalid_tenant) AADSTS90002: Tenant 'test' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 46a918f0-466a-45b6-a9a1-b860fa442500 Correlation ID: f46220c1-fd89-4dee-8a8f-780b6f4c6cc5 Timestamp: 2026-04-14 00:43:58Z\n","links":[{"title":"azd auth login reference","url":"https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login"}],"message":"Authentication with Azure failed.","suggestion":"Run 'azd auth login' to sign in again."}
```

From v1.24.0 onwards, the extraneous `\n` console message will be filtered out (#7701).

As a result, the current parsing logic won't work in newer azd versions:

Image

-------------------

There are 3 different formats we may want to add parsing logic for:

**pre v1.23.7:**

```
{"type":"consoleMessage","timestamp":"2026-04-14T22:03:37.687535934Z","data":{"message":"\nERROR: fetching token: failed to authenticate:\n(invalid_tenant) AADSTS90002: Tenant 'test' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 0646f218-6f8e-4f35-be10-2fc9c05d3d01 Correlation ID: 0806980f-59b1-4900-8e99-2a8ab623b47a Timestamp: 2026-04-14 22:03:37Z\n\n"}}
```

**[v1.23.7](https://github.com/Azure/azure-dev/releases/tag/azure-dev-cli_1.23.7) - [v1.23.15](https://github.com/Azure/azure-dev/releases/tag/azure-dev-cli_1.23.15):**

```
{"type":"consoleMessage","timestamp":"2026-04-13T17:43:24.7558297-07:00","data":{"message":"\n"}}
{"error":"fetching token: failed to authenticate:\n(invalid_tenant) AADSTS90002: Tenant 'test' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 46a918f0-466a-45b6-a9a1-b860fa442500 Correlation ID: f46220c1-fd89-4dee-8a8f-780b6f4c6cc5 Timestamp: 2026-04-14 00:43:58Z\n","links":[{"title":"azd auth login reference","url":"https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login"}],"message":"Authentication with Azure failed.","suggestion":"Run 'azd auth login' to sign in again."}
```

**v1.24.0 and newer:**
```
{"error":"fetching token: failed to authenticate:\n(invalid_tenant) AADSTS90002: Tenant 'test' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 46a918f0-466a-45b6-a9a1-b860fa442500 Correlation ID: f46220c1-fd89-4dee-8a8f-780b6f4c6cc5 Timestamp: 2026-04-14 00:43:58Z\n","links":[{"title":"azd auth login reference","url":"https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login"}],"message":"Authentication with Azure failed.","suggestion":"Run 'azd auth login' to sign in again."}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.