Get-DbaDatabase - Stop eating the caller loop on invalid parameter combination - #10637
Merged
Merged
Conversation
…mbination The begin block validation for -ExcludeUser plus -ExcludeSystem called Stop-Function -Continue, but no loop encloses that call, so without -EnableException the continue escaped the command and consumed an iteration of whatever loop the caller was running in. A script looping over instances with that parameter mistake lost every single iteration: the new regression test measures exactly that - a foreach over three elements completed zero of them on the unfixed command. Same defect class as the two sites fixed in Restore-DbaDatabase (#10636). The call now stops and returns; Test-FunctionInterrupt in the process block already handles the rest. Found by an AST sweep over all 1591 Stop-Function -Continue sites for calls without an enclosing loop or switch; this is the first fix of that inventory, chosen because Get-DbaDatabase is the most used command in the module. Verified via the lab harness on SQL03\SQL2019: 17 tests, 0 failed; the unfixed command fails the new test with "Expected 3, but got 0". (do Get-DbaDatabase) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Aug 29, 2026
Stop-Function -Continue without an enclosing loop escapes the command and corrupts the caller
#10638
Open
potatoqualitee
approved these changes
Aug 30, 2026
potatoqualitee
left a comment
Member
There was a problem hiding this comment.
Reviewed the complete current head, begin/process interruption behavior, regression coverage, and exact-head CI evidence. No material correctness or compatibility issues found.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First fix from the
Stop-Function -Continuesweep that PR #10636 triggered. The begin-block validation for-ExcludeUserplus-ExcludeSystemcalledStop-Function -Continue, but no loop encloses that call: without-EnableException, thecontinueescapes the command and consumes an iteration of whatever loop the caller is running in. Because the begin block runs once before anything else, a script looping over instances with that parameter mistake loses every iteration - the regression test demonstrates aforeachover three elements completing zero of them on the unfixed command ("Expected 3, but got 0").Fix
Drop
-Continue, addreturn- theTest-FunctionInterruptguard at the top of the process block already handles the rest. Same shape as the two end-block sites fixed in Restore-DbaDatabase (#10636), with a comment stating why-Continueis forbidden there.The sweep behind it
An AST pass over all 1591
Stop-Function -Continue/-SilentlyContinuecall sites inpublic/andprivate/functions/found 91 without an enclosing loop or switch in their function body (31 in begin blocks, 23 in process, 25 in end, 12 in nested helpers that need call-graph triage). Each affected command will get its own PR; this one goes first becauseGet-DbaDatabaseis the most used command in the module and the site fires on a plain parameter mistake.Tests
Lab harness on SQL03\SQL2019: 17 tests, 0 failed. The new test loops three times over the invalid combination, asserts all three iterations complete, and asserts the warning text - red on the unfixed command, green on the fix.
created by Claude and reviewed by Andreas Jordan
🤖 Generated with Claude Code