Report CLI errors without a secondary PowerShell exception
Config Central CI Config Central passed all CI integrity checks.
Beffroi/config-central/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-10-19 13:51:42 +02:00
parent c85679e86c
commit 557440b4ea
3 changed files with 19 additions and 1 deletions

View File

@ -130,3 +130,4 @@ open until it is run on disposable machines with the required account setups.
- [x] Apply the force-by-default policy during install/bootstrap too, with a preserve-local-configs opt-out.
- [x] Replace bootstrap exit-code exceptions with friendly partial-success, reboot, and busy summaries while preserving automation status.
- [x] Avoid null temporary-file cleanup after registry deployment or config adoption; preserve original per-item errors.
- [x] Report CLI exceptions concisely on stderr without throwing from the error handler; preserve exit code 2 and JSON errors.

2
cc.ps1
View File

@ -41,6 +41,6 @@ try {
}
catch {
$errorResult = [ordered]@{ command = $Command; succeeded = $false; exitCode = 2; error = $_.Exception.Message }
if ($Json) { $errorResult | ConvertTo-Json -Depth 8 } else { Write-Error $errorResult.error }
if ($Json) { $errorResult | ConvertTo-Json -Depth 8 } else { [Console]::Error.WriteLine("Config Central could not complete: " + $errorResult.error) }
exit 2
}

17
tests/Cli.Tests.ps1 Normal file
View File

@ -0,0 +1,17 @@
Describe 'CLI error reporting' {
It 'prints a concise error and preserves exit code 2' {
$output = & (Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' })) -NoProfile -File "$PSScriptRoot/../cc.ps1" plan -Machine missing-test-machine -DataRoot "$TestDrive/data" 2>&1
$LASTEXITCODE | Should -Be 2
($output | Out-String) | Should -Match 'Config Central could not complete:'
($output | Out-String) | Should -Not -Match 'Write-Error:|CategoryInfo|FullyQualifiedErrorId'
}
It 'keeps structured errors available to automation' {
$output = & (Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' })) -NoProfile -File "$PSScriptRoot/../cc.ps1" plan -Machine missing-test-machine -DataRoot "$TestDrive/data" -Json
$LASTEXITCODE | Should -Be 2
$result = $output | ConvertFrom-Json
$result.succeeded | Should -BeFalse
$result.exitCode | Should -Be 2
$result.error | Should -Not -BeNullOrEmpty
}
}