Invoke-DbaDbDecryptObject - Stop eating the caller loop when the export folder cannot be created - #10706
Open
andreasjordan wants to merge 2 commits into
Open
Conversation
…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
approved these changes
Sep 13, 2026
potatoqualitee
left a comment
Member
There was a problem hiding this comment.
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.
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.
Part of #10638, the sweep for
Stop-Function -Continueoutside an enclosing loop. Same shape as #10637.Problem
Invoke-DbaDbDecryptObjectguards the creation of-ExportDestinationin its begin block withStop-Function -Continue(public/Invoke-DbaDbDecryptObject.ps1:214). 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. The guard itself turned out to be dead: a failingNew-Itemis 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 -Forcereturns quietly for it on both editions, even with-ErrorAction Stop.)What changed
The
-Continueis dropped and an explicitreturnends the begin block, as in #10637; the process block is already guarded byTest-FunctionInterrupt.New-Itemgets-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 theCouldn't create destination folderwarning. 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