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
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:
parent
c85679e86c
commit
557440b4ea
1
TASKS.md
1
TASKS.md
|
|
@ -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
2
cc.ps1
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue