From 1ed3150def74e7a5c3e4d0ae77a4bdc1b5652e13 Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Sat, 12 Sep 2026 15:25:42 +0200 Subject: [PATCH 1/2] Expand-DbaDbLogFile - Stop eating the caller loop when the log file processing fails 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 message of that catch also read a variable that does not exist ($_InvocationInfo), so the line number was always empty; it is $_.InvocationInfo now. The catch wraps the whole process block and its inner failures are caught by the per-database loop, so no lab trigger for the outer catch was found; the fix mirrors the pattern of #10637. Part of #10638 (do Expand-DbaDbLogFile) Co-Authored-By: Claude Fable 5.1 --- public/Expand-DbaDbLogFile.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/Expand-DbaDbLogFile.ps1 b/public/Expand-DbaDbLogFile.ps1 index 21429747068..e519820531d 100644 --- a/public/Expand-DbaDbLogFile.ps1 +++ b/public/Expand-DbaDbLogFile.ps1 @@ -686,7 +686,9 @@ function Expand-DbaDbLogFile { } | Select-DefaultView -ExcludeProperty LogFileCount } #foreach database } catch { - Stop-Function -Message "Logfile $logfile on database $dbName not processed. Error: $($_.Exception.Message). Line Number: $($_InvocationInfo.ScriptLineNumber)" -Continue + # No -Continue here: this block has no enclosing loop, so the continue would escape the command + # and eat an iteration of whatever loop the caller runs in (#10638). + Stop-Function -Message "Logfile $logfile on database $dbName not processed. Error: $($_.Exception.Message). Line Number: $($_.InvocationInfo.ScriptLineNumber)" } } From 6296eaad13945d220ff3d307d9f474b1d6c0c8ab Mon Sep 17 00:00:00 2001 From: Andreas Jordan Date: Sat, 12 Sep 2026 18:15:24 +0200 Subject: [PATCH 2/2] Expand-DbaDbLogFile - Let the TargetVlfCount unit test really run CI showed the mocked "TargetVlfCount planning" test failing once the escaping continue was gone: the test had never run past the command call, because the catch's continue ended the It block before its assertions. The mocked run always ended in that catch, for three reasons in a row: $Databases.Count was null for a single PSCustomObject (the three filter assignments now wrap their result in @(), harmless for SMO), the Pester mock of Measure-DbaDbVirtualLogFile kept the DbaInstanceParameter binding that rejects the mocked server (now a plain function like the other stubs in the file), and the Select-DefaultView stub had no -ExcludeProperty. Part of #10638 (do Expand-DbaDbLogFile) Co-Authored-By: Claude Fable 5.1 --- public/Expand-DbaDbLogFile.ps1 | 6 +++--- tests/Expand-DbaDbLogFile.Tests.ps1 | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/public/Expand-DbaDbLogFile.ps1 b/public/Expand-DbaDbLogFile.ps1 index e519820531d..6d5ea8017c0 100644 --- a/public/Expand-DbaDbLogFile.ps1 +++ b/public/Expand-DbaDbLogFile.ps1 @@ -369,13 +369,13 @@ function Expand-DbaDbLogFile { # We don't have windows credentials here, so Resolve-DbaNetworkName has to respect that and work like Resolve-NetBiosName did before. $resolvedComputerName = Resolve-DbaComputerName -ComputerName $SqlInstance - $databases = $server.Databases | Where-Object IsAccessible + $databases = @($server.Databases | Where-Object IsAccessible) Write-Message -Level Verbose -Message "Number of databases found: $($databases.Count)." if ($Database) { - $databases = $databases | Where-Object Name -In $Database + $databases = @($databases | Where-Object Name -In $Database) } if ($ExcludeDatabase) { - $databases = $databases | Where-Object Name -NotIn $ExcludeDatabase + $databases = @($databases | Where-Object Name -NotIn $ExcludeDatabase) } #go through all databases diff --git a/tests/Expand-DbaDbLogFile.Tests.ps1 b/tests/Expand-DbaDbLogFile.Tests.ps1 index e4cd04f999f..0a96fde4c83 100644 --- a/tests/Expand-DbaDbLogFile.Tests.ps1 +++ b/tests/Expand-DbaDbLogFile.Tests.ps1 @@ -75,7 +75,8 @@ Describe $CommandName -Tag UnitTests { function Select-DefaultView { param( [Parameter(ValueFromPipeline)] - $InputObject + $InputObject, + $ExcludeProperty ) process { @@ -92,7 +93,9 @@ Describe $CommandName -Tag UnitTests { Mock Connect-DbaInstance { $script:mockServer } - Mock Measure-DbaDbVirtualLogFile { + function Measure-DbaDbVirtualLogFile { + param($SqlInstance, $Database) + $script:measureCallCount += 1 if ($script:measureCallCount -eq 1) {