Skip to content

Invoke-DbaDbDecryptObject - Stop eating the caller loop when the export folder cannot be created - #10706

Open
andreasjordan wants to merge 2 commits into
developmentfrom
fix-invoke-dbadbdecryptobject-continue-escape
Open

Invoke-DbaDbDecryptObject - Stop eating the caller loop when the export folder cannot be created#10706
andreasjordan wants to merge 2 commits into
developmentfrom
fix-invoke-dbadbdecryptobject-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

Invoke-DbaDbDecryptObject guards the creation of -ExportDestination in its begin block with Stop-Function -Continue (public/Invoke-DbaDbDecryptObject.ps1:214). 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. The guard itself turned out to be dead: a failing New-Item is not a terminating error, so the catch never ran, a folder that could not be created was silently ignored, and the export failed later. In the lab, three calls with a destination on a drive letter that does not exist left the loop counter at 3 on development - because the catch never fired - and wrote no warning. (A folder under a file is no trigger at all: New-Item -Force returns quietly for it on both editions, even with -ErrorAction Stop.)

What changed

The -Continue is dropped and an explicit return ends the begin block, as in #10637; the process block is already guarded by Test-FunctionInterrupt. New-Item gets -ErrorAction Stop, so the guard fires as designed.

Tests

New context When the export destination cannot be created: three calls with a destination on a drive letter that is free at test time, asserting the loop count and the Couldn't create destination folder warning. Through the testing-dbatools harness: green on both editions with the fix; on development the test fails on the missing warning, since the guard never fired there.

created by Claude and reviewed by Andreas Jordan

🤖 Generated with Claude Code

andreasjordan and others added 2 commits September 12, 2026 15:25
…rt folder cannot be created

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.

The guard itself was dead as well: the failing New-Item was not a
terminating error, so a folder that could not be created was ignored and
the export failed later. New-Item now stops, so the guard fires as designed.
Part of #10638

(do Invoke-DbaDbDecryptObject)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…t does not exist

New-Item -Force on a folder under a file returns quietly on both editions,
a missing drive is what makes it throw.

(do Invoke-DbaDbDecryptObject)

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 export-folder failure now returns from the helper scope rather than terminating the caller loop. Successful decryption/export behavior is unchanged, and all applicable exact-head CI 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