[PR #5356] Rework error handling and state flow in the Azure connection #26283

Open
opened 2026-01-31 09:15:07 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/5356

State: closed
Merged: Yes


38429b56c - az: rework tenant/tenant storage and fix display names

Instead of passing around four loose variables, create a Tenant class
and use that for packing/unpacking into/out of json (and the windows
credential store, where we "cleverly" used json for the tenant info
there too).

When displaying a tenant, use its display name if there is one, the
unknown resource string if there isn't, and the default domain if there
is one and the ID if there isn't.

Fixes #5325.

9f6ebcb67 - az: use {fmt} for formatting request bodies

8a54e098d - az: remove dead strings

8985c3831 - az: rework Request/HeaderHelper to Send(Authenticated?)ReqReturningJson

7ad9e8827 - az: rewrite polling to use std::chrono

69b59cb3f - az: remove HR returns from state machine

2fe5f66ea - az: rename state handlers from _XHelper to _RunXState

a1de8c37b - az: cleanup, prefix user input with >, remove namespaces

b5e16c27c - az: show more tenant info

Switch to 2020 tenant API; use defaultDomain; put defaultDomain into the
display name.

Consider: not showing the tenant GUID at all?

61f06e7aa - az: rework error handling

  • _RequestHelper no longer eats exceptions.
  • Delete the "no internet" error message.
  • Wrap exceptions coming out of Azure API in a well-known type.
  • Catch by type.
  • Extract error codes for known failures (keep polling, invalid grant).
  • When we get an Invalid Grant, dispose of the cached refresh token and force the user to log in again.
  • Catch all printable exceptions and print them.
  • Remove the NoConnect state completely -- just bail out when an exception hits the toplevel of the output thread.
  • Move 3x logic into _RefreshTokens and pop exceptions out of it.
  • Begin abstracting into AzureClient

Summary of the Pull Request

This is a tidying-up of the azure connection. It improves error logging (like: it actually emits error logs...) and retry logic and the state machine and it audits the exit points of the state machine for exceptions and removes the HRESULT returns (so they either succeed and transition to a new state or throw an exception or are going down anyway).

There's also a change in here that changes how we display tenants. It adds the "default domain" to the name, so that instead of seeing this:

Conhost (aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
Default Directory (bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb)

you see this

Conhost (conhost.onmicrosoft.com)
Default Directory (dustinhowett.onmicrosoft.com)

References

Fixes #5325 (by addressing its chief complaint).
Fixes #4803.
Adds diagnosability for #4575.

PR Checklist

  • Closes #5325. Closes #4803.
  • CLA
  • Tests added/passed
  • Requires documentation to be updated
  • Core contributor

Detailed Description of the Pull Request / Additional comments

As above.

Validation Steps Performed

Logged in, out, around a good number of times.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/5356 **State:** closed **Merged:** Yes --- ### 38429b56c - az: rework tenant/tenant storage and fix display names Instead of passing around four loose variables, create a Tenant class and use that for packing/unpacking into/out of json (and the windows credential store, where we "cleverly" used json for the tenant info there too). When displaying a tenant, use its display name if there is one, the unknown resource string if there isn't, and the default domain if there is one and the ID if there isn't. Fixes #5325. ### 9f6ebcb67 - az: use {fmt} for formatting request bodies ### 8a54e098d - az: remove dead strings ### 8985c3831 - az: rework Request/HeaderHelper to Send(Authenticated?)ReqReturningJson ### 7ad9e8827 - az: rewrite polling to use std::chrono ### 69b59cb3f - az: remove HR returns from state machine ### 2fe5f66ea - az: rename state handlers from _XHelper to _RunXState ### a1de8c37b - az: cleanup, prefix user input with >, remove namespaces ### b5e16c27c - az: show more tenant info Switch to 2020 tenant API; use defaultDomain; put defaultDomain into the display name. Consider: not showing the tenant GUID at all? ### 61f06e7aa - az: rework error handling * _RequestHelper no longer eats exceptions. * Delete the "no internet" error message. * Wrap exceptions coming out of Azure API in a well-known type. * Catch by type. * Extract error codes for known failures (keep polling, invalid grant). * When we get an Invalid Grant, dispose of the cached refresh token and force the user to log in again. * Catch all printable exceptions and print them. * Remove the NoConnect state completely -- just bail out when an exception hits the toplevel of the output thread. * Move 3x logic into _RefreshTokens and pop exceptions out of it. * Begin abstracting into AzureClient ## Summary of the Pull Request This is a tidying-up of the azure connection. It improves error logging (like: it actually emits error logs...) and retry logic and the state machine and it audits the exit points of the state machine for exceptions and removes the HRESULT returns (so they either succeed and transition to a new state or throw an exception or are going down anyway). There's also a change in here that changes how we display tenants. It adds the "default domain" to the name, so that instead of seeing this: ``` Conhost (aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa) Default Directory (bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb) ``` you see this ``` Conhost (conhost.onmicrosoft.com) Default Directory (dustinhowett.onmicrosoft.com) ``` # References Fixes #5325 (by addressing its chief complaint). Fixes #4803. Adds diagnosability for #4575. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [x] Closes #5325. Closes #4803. * [x] CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [x] Core contributor ## Detailed Description of the Pull Request / Additional comments As above. ## Validation Steps Performed Logged in, out, around a good number of times.
claunia added the pull-request label 2026-01-31 09:15:07 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26283