Copy-DbaDatabase - Stop eating the caller loop when a system database is requested - #10696
Conversation
… is requested Stop-Function -Continue runs PowerShell's continue. No loop encloses the system database check inside the process block, 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 Copy-DbaDatabase) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
potatoqualitee
left a comment
There was a problem hiding this comment.
public/Copy-DbaDatabase.ps1:779-780 still suppresses valid later pipeline inputs after one unsupported system database. Stop-Function without -Continue sets the command-scope interrupt flag; the explicit return ends only the current process invocation, and the next piped database is then rejected by Test-FunctionInterrupt at lines 729-731. For example, piping master followed by an application database warns for master and silently skips the application database. The new test calls the command three separate times, so it does not exercise this single-pipeline path.
Please preserve the warning/error behavior without leaving the command-wide interrupt flag set for this per-input rejection, and add a regression test with a system database followed by a valid database in one pipeline.
…bases piped in after it A plain Stop-Function set the function-scope interrupt flag, so after one system database Test-FunctionInterrupt dropped every later piped database. Throw under -EnableException, otherwise warn, and return from that process invocation only. Adds one-pipeline and -EnableException tests. (do Copy-DbaDatabase) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(do Copy-DbaDatabase) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…er form A throw inside the process block of a piped call surfaces in the upstream command, whose own output loop catches it. (do Copy-DbaDatabase) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Confirmed and fixed in 2ecac8b: the plain What changed: the system-database check now throws under Tests: the context gained a fixture database on created by Claude and reviewed by Andreas Jordan |
potatoqualitee
left a comment
There was a problem hiding this comment.
The current head resolves my previous pipeline-control-flow finding, including coverage that a valid database following a system database is still processed. No material defects remain. Reviewed at head 2ecac8b.
| if ($EnableException) { | ||
| Stop-Function -Message $systemDbMessage -EnableException $true | ||
| } | ||
| Write-Message -Level Warning -Message $systemDbMessage |
There was a problem hiding this comment.
I'm not so sure this makes sense. it'll show duplicate if the person has enableexception enabled it'll warn them twice.
There was a problem hiding this comment.
It never warned twice, but I agree the shape suggested it could: under -EnableException, Stop-Function throws before the next line is reached, so the Write-Message after it was dead code on that path. Fixed in c3d4df0 by making it an explicit if/else.
Measured on the lab, pwsh and 5.1: the exception path emits the exception and one warning record (the one Stop-Function itself writes before every throw in dbatools; a console shows only the exception), the warning path emits exactly one warning. Both are asserted now: the throw test runs the command in the test scope with its own warning variable and checks one record, the loop test checks that the last rejected call warned once. The whole file is green on both editions (31/31).
created by Claude and reviewed by Andreas Jordan
…n-or-throw Under -EnableException the Stop-Function call throws before the line after it runs, so the warning was never written a second time, but the shape read as if it could be. Put the two paths into one if/else. The throw test now runs the command in the test scope with its own warning variable and asserts one warning record next to the exception, the one Stop-Function writes before every throw, and the loop test asserts that the last rejected call warned exactly once. (do Copy-DbaDatabase) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
potatoqualitee
left a comment
There was a problem hiding this comment.
No material defects found.
|
ty 🙇🏼 |
Part of #10638, the sweep for
Stop-Function -Continueoutside an enclosing loop. Same shape and same test as #10637.Problem
Copy-DbaDatabaserefuses system databases withStop-Function -Continuein its process block (Copy-DbaDatabase.ps1:777). No loop encloses that site inside the command, so without-EnableExceptionthecontinueunwinds out of the command and consumes an iteration of whatever loop the caller runs in. Proven in the lab with the plain-script recipe: three calls with-Database masterin aforeachleft the loop counter at 0 on development and at 3 with the fix.What changed
The
-Continueis dropped and an explicitreturnends the process block for that input, as in #10637. Nothing else changes; the check still fires before any connection is made.Tests
New context
When a system database is requested: three calls in a loop, asserting the loop count and the warning. Through the testing-dbatools harness: green on both editions with the fix (28 passed); the plain-script proof above is the red-on-old.created by Claude and reviewed by Andreas Jordan
🤖 Generated with Claude Code