Bug Description
In Invoke-ServyCli, the $LASTEXITCODE check is inside a try/catch block. When the CLI returns a non-zero exit code, the throw on line 212 is caught by its own catch block on line 215, resulting in a double-wrapped error message.
Actual Behavior
The current code:
try {
& $script:ServyCliPath $finalArgs
if ($LASTEXITCODE -ne 0) {
throw "Servy CLI exited with code $LASTEXITCODE" # line 212
}
}
catch {
throw "$($ErrorContext): $_" # line 216 catches its own throw
}
When the CLI exits with code 1, the error becomes:
Failed to start service 'MyService': Servy CLI exited with code 1
This works, but the try/catch was intended for real exceptions (e.g. executable not found, access denied), not for exit code handling. The exit code throw is unintentionally caught by its own catch block.
Suggested Fix
Move the exit code check outside the try/catch so each error type is handled separately:
try {
& $script:ServyCliPath $finalArgs
}
catch {
throw "$($ErrorContext): $_"
}
if ($LASTEXITCODE -ne 0) {
throw "$($ErrorContext): Servy CLI exited with code $LASTEXITCODE"
}
This way:
- Exceptions (file not found, access denied) are caught by
catch
- Non-zero exit codes are handled explicitly after successful execution
Environment
- PowerShell module:
Servy.psm1
- Affects:
Invoke-ServyCli function (lines 193–218)
Bug Description
In
Invoke-ServyCli, the$LASTEXITCODEcheck is inside atry/catchblock. When the CLI returns a non-zero exit code, thethrowon line 212 is caught by its owncatchblock on line 215, resulting in a double-wrapped error message.Actual Behavior
The current code:
When the CLI exits with code 1, the error becomes:
This works, but the
try/catchwas intended for real exceptions (e.g. executable not found, access denied), not for exit code handling. The exit code throw is unintentionally caught by its own catch block.Suggested Fix
Move the exit code check outside the
try/catchso each error type is handled separately:This way:
catchEnvironment
Servy.psm1Invoke-ServyClifunction (lines 193–218)