Skip to content

New-DbaAzAccessToken - Stop eating the caller loop when the token request fails - #10700

Open
andreasjordan wants to merge 2 commits into
developmentfrom
fix-new-dbaazaccesstoken-continue-escape
Open

New-DbaAzAccessToken - Stop eating the caller loop when the token request fails#10700
andreasjordan wants to merge 2 commits into
developmentfrom
fix-new-dbaazaccesstoken-continue-escape

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Part of #10638, the sweep for Stop-Function -Continue outside an enclosing loop. Same shape as #10637.

Problem

New-DbaAzAccessToken reports a failed token request from the catch at the end of its process block with Stop-Function -Continue (public/New-DbaAzAccessToken.ps1:257). No loop encloses that site inside the command, so without -EnableException the continue unwinds out of the command and consumes an iteration of whatever loop the caller runs in. Proven in the lab on Windows PowerShell with the plain-script recipe: three ServicePrincipal calls with a tenant that does not exist left the loop counter at 0 on development. The catch is reachable there because the ADAL type the path uses is not present, which throws; on PowerShell Core the path refuses to run before any request is made, so the catch cannot be reached that way.

What changed

The -Continue is dropped; the catch is the last statement of the process block, so nothing else is needed.

Tests

The test file had no integration tests. New context When the service principal cannot be authenticated: three calls in a loop, asserting the loop count and the Failure warning, skipped on Core with a comment saying why. Through the testing-dbatools harness: green on Windows PowerShell with the fix; the plain-script proof above is the red-on-old.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

andreasjordan and others added 2 commits September 12, 2026 15:25
…uest fails

Stop-Function -Continue runs PowerShell's continue. No loop encloses this
call site inside the command, so the continue unwound out of the command
and consumed an iteration of whatever loop the caller runs in: a user's
foreach silently skipped an element, and Pester's runner corrupted. The
escape only bites the non-EnableException path; with EnableException
Stop-Function throws before it gets there.

Part of #10638

(do New-DbaAzAccessToken)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…, where the ServicePrincipal path executes

(do New-DbaAzAccessToken)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@potatoqualitee potatoqualitee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The token-request failure now returns from the command invocation instead of consuming the caller loop, without changing successful token acquisition. The targeted Windows PowerShell coverage and all applicable exact-head checks pass.

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.

2 participants