Skip to content

Commit

Permalink
(GH-707) Exit with specific exit codes
Browse files Browse the repository at this point in the history
When running PowerShell and certain things are found, exit
appropriately.

- When a file is not found, exit 2.
- When a file found is not right, exit 4.
- When a file can not be downloaded, exit 404.
- When unzipping has issues, exit with its result exit code
  • Loading branch information
ferventcoder committed Apr 24, 2016
1 parent d7b4de5 commit cfa8e2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ param(
Unregister-Event -SourceIdentifier "LogErrors_ChocolateyZipProc"

$exitCode = $process.ExitCode
Set-PowerShellExitCode $exitCode
$process.Dispose()
Write-Debug "Command ['$7zip' $params] exited with `'$exitCode`'."

Expand Down
1 change: 1 addition & 0 deletions src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ param(
[GC]::Collect()
}

Set-PowerShellExitCode 404
throw "The remote file either doesn't exist, is unauthorized, or is forbidden for url '$url'. $($_.Exception.Message)"
} finally {
if ($res -ne $null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,15 @@ Elevating Permissions and running [`"$exeToRun`" $wrappedStatements]. This may t

$exeIsTextFile = [System.IO.Path]::GetFullPath($exeToRun) + ".istext"
if (([System.IO.File]::Exists($exeIsTextFile))) {
Set-PowerShellExitCode 4
throw "The file was a text file but is attempting to be run as an executable - '$exeToRun'"
}

if (!([System.IO.File]::Exists($exeToRun))) {
Set-PowerShellExitCode 2
throw "Could not find '$exeToRun'"
}

# Redirecting output slows things down a bit.
$writeOutput = {
if ($EventArgs.Data -ne $null) {
Expand Down

0 comments on commit cfa8e2f

Please sign in to comment.