Skip to content

Commit

Permalink
Merge pull request #1199 from axodotdev/fix-ps1-errors
Browse files Browse the repository at this point in the history
fix: handle Invoke-Installer errors
  • Loading branch information
Gankra authored Jul 11, 2024
2 parents 5eebe17 + eed524b commit 4f6c91a
Show file tree
Hide file tree
Showing 36 changed files with 468 additions and 144 deletions.
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -270,15 +279,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1297,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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1311,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1316,15 +1325,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1296,15 +1305,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1297,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1297,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1311,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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1302,15 +1311,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
17 changes: 13 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,16 @@ 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 below.

$_
"@
}
}

function Get-TargetTriple() {
Expand Down Expand Up @@ -1288,15 +1297,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 4f6c91a

Please sign in to comment.