From dec41f69c3b7fb64ea3f2cdba507709053d4d4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Thu, 14 Dec 2023 15:23:56 -0800 Subject: [PATCH] fix(powershell): replace errors with throw Co-authored-by: Aria Beingessner Fixes #484. --- .../templates/installer/installer.ps1.j2 | 45 ++++++++++++------- .../tests/snapshots/akaikatana_basic.snap | 44 +++++++++++------- .../akaikatana_repo_with_dot_git.snap | 44 +++++++++++------- .../tests/snapshots/axolotlsay_abyss.snap | 44 +++++++++++------- .../snapshots/axolotlsay_abyss_only.snap | 44 +++++++++++------- .../tests/snapshots/axolotlsay_basic.snap | 44 +++++++++++------- .../snapshots/axolotlsay_edit_existing.snap | 44 +++++++++++------- .../axolotlsay_no_homebrew_publish.snap | 44 +++++++++++------- .../axolotlsay_ssldotcom_windows_sign.snap | 44 +++++++++++------- ...xolotlsay_ssldotcom_windows_sign_prod.snap | 44 +++++++++++------- .../axolotlsay_user_global_build_job.snap | 44 +++++++++++------- .../snapshots/axolotlsay_user_host_job.snap | 44 +++++++++++------- .../axolotlsay_user_local_build_job.snap | 44 +++++++++++------- .../snapshots/axolotlsay_user_plan_job.snap | 44 +++++++++++------- .../axolotlsay_user_publish_job.snap | 44 +++++++++++------- .../snapshots/install_path_cargo_home.snap | 44 +++++++++++------- .../snapshots/install_path_env_no_subdir.snap | 44 +++++++++++------- .../snapshots/install_path_env_subdir.snap | 44 +++++++++++------- .../install_path_env_subdir_space.snap | 44 +++++++++++------- .../install_path_env_subdir_space_deeper.snap | 44 +++++++++++------- .../install_path_home_subdir_deeper.snap | 44 +++++++++++------- .../install_path_home_subdir_min.snap | 44 +++++++++++------- .../install_path_home_subdir_space.snap | 44 +++++++++++------- ...install_path_home_subdir_space_deeper.snap | 44 +++++++++++------- 24 files changed, 672 insertions(+), 385 deletions(-) diff --git a/cargo-dist/templates/installer/installer.ps1.j2 b/cargo-dist/templates/installer/installer.ps1.j2 index a9a6bc5be..65e78e890 100644 --- a/cargo-dist/templates/installer/installer.ps1.j2 +++ b/cargo-dist/templates/installer/installer.ps1.j2 @@ -52,13 +52,11 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment # Platform info injected by cargo-dist - $platforms = @{ + $platforms = @{ {%- for artifact in artifacts %} "{{ artifact.target_triples[0] }}" = @{ "artifact_name" = "{{ artifact.id }}" @@ -73,8 +71,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -272,26 +268,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -307,5 +312,11 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} diff --git a/cargo-dist/tests/snapshots/akaikatana_basic.snap b/cargo-dist/tests/snapshots/akaikatana_basic.snap index 37e5d7411..1310e56ca 100644 --- a/cargo-dist/tests/snapshots/akaikatana_basic.snap +++ b/cargo-dist/tests/snapshots/akaikatana_basic.snap @@ -852,8 +852,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -869,8 +867,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1052,26 +1048,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1087,7 +1092,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap b/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap index 37e5d7411..1310e56ca 100644 --- a/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap +++ b/cargo-dist/tests/snapshots/akaikatana_repo_with_dot_git.snap @@ -852,8 +852,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -869,8 +867,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1052,26 +1048,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1087,7 +1092,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap index 4a47916be..a7fe5e5d7 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap index 36d079ee8..4d048b740 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_abyss_only.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_basic.snap b/cargo-dist/tests/snapshots/axolotlsay_basic.snap index 59c94a394..85c313190 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_basic.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_basic.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap index 52230b443..6651ada4b 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_edit_existing.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap index 2ab9bd2eb..a52a95c87 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_no_homebrew_publish.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap index 37ecac3ac..7647c0315 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign.snap @@ -821,8 +821,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -838,8 +836,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1021,26 +1017,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1056,7 +1061,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap index 3df4b2617..348a0cf9a 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_ssldotcom_windows_sign_prod.snap @@ -821,8 +821,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -838,8 +836,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1021,26 +1017,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1056,7 +1061,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap index 3954440aa..09da2fa76 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_global_build_job.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap index 001ca40f9..180ff236f 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_host_job.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap index 86d16b64a..41f99456d 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_local_build_job.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap index e54e40661..f7edc56ff 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_plan_job.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap index ad2cdea4f..75c5723bb 100644 --- a/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap +++ b/cargo-dist/tests/snapshots/axolotlsay_user_publish_job.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ npm-package.tar.gz/package/.gitignore ================ /node_modules diff --git a/cargo-dist/tests/snapshots/install_path_cargo_home.snap b/cargo-dist/tests/snapshots/install_path_cargo_home.snap index d6d8816b4..a374e1c0a 100644 --- a/cargo-dist/tests/snapshots/install_path_cargo_home.snap +++ b/cargo-dist/tests/snapshots/install_path_cargo_home.snap @@ -853,8 +853,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -870,8 +868,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1053,26 +1049,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1088,7 +1093,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap b/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap index f4f77975d..34116db4e 100644 --- a/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_no_subdir.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir.snap b/cargo-dist/tests/snapshots/install_path_env_subdir.snap index 5af42fef8..9a13fa299 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap b/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap index 8192732b7..dc2d89a07 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir_space.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap b/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap index 1eba595e5..6e82c669f 100644 --- a/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_env_subdir_space_deeper.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap index 93e93a7b5..e328223ed 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_deeper.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap index 32c368279..6f4d2dbac 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_min.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap index 0dfad5498..af7f7badd 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_space.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ { diff --git a/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap b/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap index c50376218..ee17fde12 100644 --- a/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap +++ b/cargo-dist/tests/snapshots/install_path_home_subdir_space_deeper.snap @@ -836,8 +836,6 @@ function Install-Binary($install_args) { Get-Help $PSCommandPath -Detailed Exit } - $old_erroractionpreference = $ErrorActionPreference - $ErrorActionPreference = 'stop' Initialize-Environment @@ -853,8 +851,6 @@ function Install-Binary($install_args) { $fetched = Download "$ArtifactDownloadUrl" $platforms # FIXME: add a flag that lets the user not do this step Invoke-Installer $fetched "$install_args" - - $ErrorActionPreference = $old_erroractionpreference } function Get-TargetTriple() { @@ -1033,26 +1029,35 @@ function Add-Path($OrigPathToAdd) { function Initialize-Environment() { If (($PSVersionTable.PSVersion.Major) -lt 5) { - Write-Error "PowerShell 5 or later is required to install $app_name." - Write-Error "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" - break + throw @" +Error: PowerShell 5 or later is required to install $app_name. +Upgrade PowerShell: + + https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell + +"@ } # show notification to change execution policy: $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass') If ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) { - Write-Error "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name." - Write-Error "For example, to set the execution policy to 'RemoteSigned' please run :" - Write-Error "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'" - break + throw @" +Error: PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run $app_name. For example, to set the execution policy to 'RemoteSigned' please run: + + Set-ExecutionPolicy RemoteSigned -scope CurrentUser + +"@ } # GitHub requires TLS 1.2 If ([System.Enum]::GetNames([System.Net.SecurityProtocolType]) -notcontains 'Tls12') { - Write-Error "Installing $app_name requires at least .NET Framework 4.5" - Write-Error "Please download and install it first:" - Write-Error "https://www.microsoft.com/net/download" - break + throw @" +Error: Installing $app_name requires at least .NET Framework 4.5 +Please download and install it first: + + https://www.microsoft.com/net/download + +"@ } } @@ -1068,7 +1073,14 @@ function New-Temp-Dir() { $Null = $ArtifactDownloadUrl, $NoModifyPath, $Help # Make Write-Information statements be visible $InformationPreference = "Continue" -Install-Binary "$Args" + +# The default interactive handler +try { + Install-Binary "$Args" +} catch { + Write-Information $_ + exit 1 +} ================ dist-manifest.json ================ {