Skip to content

Commit

Permalink
fix: handle Invoke-Installer errors
Browse files Browse the repository at this point in the history
We hadn't set the error types we wanted from the core file management
functions here, so they were continuing after an error instead of
throwing so we could terminate early.

Prior to dec41f6 this was handled
by explicitly setting $ErrorActionPreference before and after
calling Invoke-Installer. We removed that when reworking some errors,
but we didn't update individual calls within Invoke-Installer to ensure
they still stopped on error.
  • Loading branch information
mistydemeo committed Jul 9, 2024
1 parent 6439c47 commit 6c8f055
Show file tree
Hide file tree
Showing 36 changed files with 432 additions and 144 deletions.
16 changes: 12 additions & 4 deletions cargo-dist/templates/installer/installer.ps1.j2
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -270,15 +278,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/akaikatana_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1296,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1310,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/akaikatana_two_bin_aliases.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1316,15 +1324,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/akaikatana_updaters.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1296,15 +1304,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/axolotlsay_abyss.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1296,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1296,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/axolotlsay_alias.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1310,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1310,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/axolotlsay_basic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1296,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-dist/tests/snapshots/axolotlsay_basic_lies.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,15 @@ function Install-Binary($install_args) {

$fetched = Download "$ArtifactDownloadUrl" $platforms
# FIXME: add a flag that lets the user not do this step
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
try {
Invoke-Installer -bin_paths $fetched -platforms $platforms "$install_args"
} catch {
throw @"
We encountered an error trying to perform the installation;
please review the error messages above.

"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1291,15 +1299,15 @@ function Invoke-Installer($bin_paths, $platforms) {
# Just copy the binaries from the temp location to the install dir
foreach ($bin_path in $bin_paths) {
$installed_file = Split-Path -Path "$bin_path" -Leaf
Copy-Item "$bin_path" -Destination "$dest_dir"
Remove-Item "$bin_path" -Recurse -Force
Copy-Item "$bin_path" -Destination "$dest_dir" -ErrorAction Stop
Remove-Item "$bin_path" -Recurse -Force -ErrorAction Stop
Write-Information " $installed_file"

if (($dests = $info["aliases"][$installed_file])) {
$source = Join-Path "$dest_dir" "$installed_file"
foreach ($dest_name in $dests) {
$dest = Join-Path $dest_dir $dest_name
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force
$null = New-Item -ItemType HardLink -Target "$source" -Path "$dest" -Force -ErrorAction Stop
}
}
}
Expand Down
Loading

0 comments on commit 6c8f055

Please sign in to comment.