Copy-DbaDatabase - Stop eating the caller loop when a system database is requested - #10696
Copy-DbaDatabase - Stop eating the caller loop when a system database is requested#10696andreasjordan wants to merge 4 commits into
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 |
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