Get-DbaBackupInformation - Stop eating the caller loop when a backup header cannot be read - #10701
Get-DbaBackupInformation - Stop eating the caller loop when a backup header cannot be read#10701andreasjordan wants to merge 4 commits into
Conversation
…header cannot be read 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. Part of #10638 (do Get-DbaBackupInformation) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…to Read-DbaBackupHeader
The S3 CI test expects "S3 paths cannot be enumerated using T-SQL" for an
s3:// folder, but an S3 URL forces the non-xp_dirtree branch, where the folder
was appended to the file list and Read-DbaBackupHeader rejected it. That
rejection used a broken string literal, "Path ("$p") should be ...", which
handed $p to Stop-Function as a positional argument and turned the warning into
a binding error. On development the escaping continue of the header-read catch
ended the CI test before its assertions, so it passed vacuously; the first
commit of this branch made it fail honestly.
An s3:// path without an extension is now reported through Stop-Function
-Continue inside the path loop, and Read-DbaBackupHeader's literal is repaired.
One regression test each.
Part of #10638
(do Get-DbaBackupInformation, Read-DbaBackupHeader)
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
The S3 workflow failure is a real finding of this PR, not a flake. It is green on What the failing test does. On Fix, pushed as a second commit:
Lab results: Get-DbaBackupInformation 20/20 and Read-DbaBackupHeader 2/2 on both PowerShell 7 and Windows PowerShell 5.1. With the two source files swapped back to the first commit, the two new tests are the only failures, and the S3 one reproduces the CI message locally ("A positional parameter cannot be found that accepts argument ..."). Created by Claude and reviewed by Andreas Jordan. |
potatoqualitee
left a comment
There was a problem hiding this comment.
public/Get-DbaBackupInformation.ps1:358-359 still drops valid later pipeline inputs after one unreadable backup. Stop-Function without -Continue sets the command-scope interrupt flag; although the explicit return ends only the current process invocation, the next piped Path reaches line 247, sees that persistent flag via Test-FunctionInterrupt, and returns without processing it. For example, piping an invalid file followed by a valid backup returns no information for the valid backup. The new test calls the command three separate times, so each call gets a fresh function scope and misses this path.
Please handle the header-read failure without leaving the command-wide interrupt flag set (or restructure per-input processing so continuation is local), and add a regression test that pipes an invalid path followed by a valid backup and asserts the valid backup is returned.
…opping the paths piped in after it A plain Stop-Function set the function-scope interrupt flag, so after one unreadable file Test-FunctionInterrupt dropped every later piped path. Throw under -EnableException, otherwise warn, and return from that process invocation only. Adds one-pipeline and -EnableException tests. (do Get-DbaBackupInformation) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…fixture and Stop-Function produce The fixture backup file can hold two backup sets, and Stop-Function rethrows the inner RESTORE HEADERONLY error under -EnableException. (do Get-DbaBackupInformation) Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Confirmed and fixed in a752106: the plain What changed: the header-read catch now throws under Tests: two new tests in the "file is not a backup" context. A text file followed by a real backup in one pipeline still returns the backup and warns for the text file; the One observation outside this PR's scope: the array form 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-input finding. No material defects remain. Reviewed at head a752106.
| # continue here (#10638). So throw under -EnableException, otherwise warn, and return from | ||
| # this process invocation only. | ||
| if ($EnableException) { | ||
| Stop-Function -Message "Failure on $($server.Name)" -ErrorRecord $PSItem -Target $server.Name -EnableException $true |
There was a problem hiding this comment.
dupe error message yeah?
Part of #10638, the sweep for
Stop-Function -Continueoutside an enclosing loop. Same shape as #10637.Problem
Get-DbaBackupInformationreports a failed header read from the catch aroundRead-DbaBackupHeader, which runs with-EnableExceptionso the catch is live withStop-Function -Continue(public/Get-DbaBackupInformation.ps1:352). 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 in aforeachleft the loop counter at 0 on development and at 3 with the fix.What changed
The
-Continueis dropped and an explicitreturnends the block for that input, as in #10637. Nothing else changes.Tests
New context
When a file is not a backup: a text file on the shared path the instance can read, three calls, asserting the loop count and theFailure onwarning. Through the testing-dbatools harness: green on both editions with the fix; the plain-script proof above is the red-on-old.created by Claude and reviewed by Andreas Jordan
🤖 Generated with Claude Code