Skip to content

Expose MsalServiceException.ErrorCodesForLogging for diagnostics - #6138

Merged
Neha Bhargava (neha-bhargava) merged 3 commits into
mainfrom
nebharg/expose-service-error-codes
Jul 22, 2026
Merged

Neha Bhargava (neha-bhargava) merged 3 commits into
mainfrom
nebharg/expose-service-error-codes

Conversation

@neha-bhargava

@neha-bhargava Neha Bhargava (neha-bhargava) commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Promote MsalServiceException.ErrorCodesForLogging from internal string[] to a public IReadOnlyList (getter only; setter stays internal).

Why

Downstream diagnostics need the raw STS-specific error codes (numeric AADSTS codes, e.g. 50076, 500011) that refine ErrorCode. They were already populated internally but not observable by callers.

Notes

  • Named ErrorCodesForLogging (matching SubErrorForLogging) to signal it is diagnostics-only; values are service-emitted and may change — not intended for branching production behavior.
  • Returns an Array.AsReadOnly view so callers cannot downcast the IReadOnlyList and mutate the exception's error codes.
  • LoggerHelper updated ({Length:>0} → {Count:>0}), the only array-specific usage.
  • OTelInstrumentationTests asserts population + the RawStsErrorCode telemetry tag.

Related

Promote ErrorCodes from internal string[] to a public
IReadOnlyList (getter only; setter stays internal) so
downstream callers can surface the raw STS error codes (numeric
AADSTS codes) for diagnostics and logging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d296b5aa-33db-4934-a697-cdf1c1999e09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 exposes MsalServiceException.ErrorCodes publicly (as IReadOnlyList) so downstream callers can access raw STS-specific error codes (e.g., numeric AADSTS codes) for diagnostics and logging.

Changes:

  • Promoted MsalServiceException.ErrorCodes from an internal string[] to a public IReadOnlyList (internal setter) and expanded the XML docs.
  • Updated LoggerHelper to use {Count: > 0} pattern matching to accommodate the new list type.
  • Added PublicAPI baseline entries across TFMs and a changelog entry for the new API.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CHANGELOG.md Adds a release note entry for exposing MsalServiceException.ErrorCodes.
src/client/Microsoft.Identity.Client/MsalServiceException.cs Makes ErrorCodes public as IReadOnlyList and updates its documentation.
src/client/Microsoft.Identity.Client/Internal/Logger/LoggerHelper.cs Updates error-codes logging guard from Length to Count.
src/client/Microsoft.Identity.Client/PublicApi/netstandard2.0/PublicAPI.Unshipped.txt Adds the new public API entry for netstandard2.0.
src/client/Microsoft.Identity.Client/PublicApi/net8.0/PublicAPI.Unshipped.txt Adds the new public API entry for net8.0.
src/client/Microsoft.Identity.Client/PublicApi/net8.0-ios/PublicAPI.Unshipped.txt Adds the new public API entry for net8.0-ios.
src/client/Microsoft.Identity.Client/PublicApi/net8.0-android/PublicAPI.Unshipped.txt Adds the new public API entry for net8.0-android.
src/client/Microsoft.Identity.Client/PublicApi/net472/PublicAPI.Unshipped.txt Adds the new public API entry for net472.
src/client/Microsoft.Identity.Client/PublicApi/net462/PublicAPI.Unshipped.txt Adds the new public API entry for net462.

Comment thread CHANGELOG.md Outdated
Comment thread src/client/Microsoft.Identity.Client/MsalServiceException.cs Outdated
Comment thread src/client/Microsoft.Identity.Client/MsalServiceException.cs Outdated
… (Bug 3696281)

- Rename the new public MsalServiceException.ErrorCodes to ErrorCodesForLogging
  per PR feedback, matching the sibling SubErrorForLogging and signalling it is
  a diagnostics-only surface (property is still unshipped, so no break).
- Wrap the backing string[] in Array.AsReadOnly so callers cannot downcast the
  IReadOnlyList and mutate the exception's error codes.
- Fix the CHANGELOG placeholder link (#TBD -> #6138) and property name.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d296b5aa-33db-4934-a697-cdf1c1999e09
Copilot AI review requested due to automatic review settings July 22, 2026 18:02
@neha-bhargava Neha Bhargava (neha-bhargava) changed the title Expose MsalServiceException.ErrorCodes for diagnostics Expose MsalServiceException.ErrorCodesForLogging for diagnostics Jul 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread src/client/Microsoft.Identity.Client/MsalServiceException.cs
Copilot AI review requested due to automatic review settings July 22, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

@neha-bhargava
Neha Bhargava (neha-bhargava) merged commit 5078abc into main Jul 22, 2026
17 checks passed
@neha-bhargava
Neha Bhargava (neha-bhargava) deleted the nebharg/expose-service-error-codes branch July 22, 2026 20:57
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.

5 participants