Skip to content

Get-DbaDatabase - Stop eating the caller loop on invalid parameter combination - #10637

Merged
potatoqualitee merged 1 commit into
developmentfrom
fix-getdbadatabase-continue-escape
Sep 1, 2026
Merged

Get-DbaDatabase - Stop eating the caller loop on invalid parameter combination#10637
potatoqualitee merged 1 commit into
developmentfrom
fix-getdbadatabase-continue-escape

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Summary

First fix from the Stop-Function -Continue sweep that PR #10636 triggered. The begin-block validation for -ExcludeUser plus -ExcludeSystem called Stop-Function -Continue, but no loop encloses that call: without -EnableException, the continue escapes 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 a foreach over three elements completing zero of them on the unfixed command ("Expected 3, but got 0").

Fix

Drop -Continue, add return - the Test-FunctionInterrupt guard 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 -Continue is forbidden there.

The sweep behind it

An AST pass over all 1591 Stop-Function -Continue/-SilentlyContinue call sites in public/ and private/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 because Get-DbaDatabase is 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

…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>

@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.

Reviewed the complete current head, begin/process interruption behavior, regression coverage, and exact-head CI evidence. No material correctness or compatibility issues found.

@potatoqualitee
potatoqualitee merged commit 45a1172 into development Sep 1, 2026
31 of 33 checks passed
@potatoqualitee
potatoqualitee deleted the fix-getdbadatabase-continue-escape branch September 1, 2026 05:40
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