Use Write-Error with ErrorAction as Stop instead of exit

This commit is contained in:
Shivam Mathur 2023-03-14 06:02:04 +05:30
parent 1b08836381
commit 5f422817a1
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
2 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@ Function Edit-ComposerConfig() {
php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}" php -r "try {`$p=new Phar('$tool_path.phar', 0);exit(0);} catch(Exception `$e) {exit(1);}"
if ($? -eq $False) { if ($? -eq $False) {
Add-Log "$cross" "composer" "Could not download composer" Add-Log "$cross" "composer" "Could not download composer"
exit 1; Write-Error "Error" -ErrorAction Stop
} }
New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1 New-Item -ItemType Directory -Path $composer_bin -Force > $null 2>&1
if (-not(Test-Path $composer_json)) { if (-not(Test-Path $composer_json)) {

View File

@ -23,7 +23,7 @@ Function Add-Log($mark, $subject, $message) {
} else { } else {
printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message printf "\033[31;1m%s \033[0m\033[34;1m%s \033[0m\033[90;1m%s \033[0m\n" $mark $subject $message
if($env:fail_fast -eq 'true') { if($env:fail_fast -eq 'true') {
exit 1; Write-Error "Error" -ErrorAction Stop
} }
} }
} }
@ -337,7 +337,7 @@ if ( $env:GITHUB_ACTIONS -eq 'true') {
if(-not($env:ImageOS) -and -not($env:ImageVersion)) { if(-not($env:ImageOS) -and -not($env:ImageVersion)) {
if($env:RUNNER -eq 'github') { if($env:RUNNER -eq 'github') {
Add-Log $cross "Runner" "Runner set as github in self-hosted environment" Add-Log $cross "Runner" "Runner set as github in self-hosted environment"
exit 1 Write-Error "Error" -ErrorAction Stop
} }
$bin_dir = 'C:\tools\bin' $bin_dir = 'C:\tools\bin'
$php_dir = "$php_dir$version" $php_dir = "$php_dir$version"
@ -348,7 +348,7 @@ if(-not($env:ImageOS) -and -not($env:ImageVersion)) {
if($version -lt 5.6) { if($version -lt 5.6) {
Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner" Add-Log $cross "PHP" "PHP $version is not supported on self-hosted runner"
Start-Sleep 1 Start-Sleep 1
exit 1 Write-Error "Error" -ErrorAction Stop
} }
if ($null -eq (Get-Module -ListAvailable -Name VcRedist)) { if ($null -eq (Get-Module -ListAvailable -Name VcRedist)) {
Install-Module -Name VcRedist -Force Install-Module -Name VcRedist -Force
@ -418,7 +418,7 @@ if($env:DEBUG -eq 'true') {
$installed = Get-Php -Path $php_dir $installed = Get-Php -Path $php_dir
if($installed.MajorMinorVersion -ne $version) { if($installed.MajorMinorVersion -ne $version) {
Add-Log $cross "PHP" "Could not setup PHP $version" Add-Log $cross "PHP" "Could not setup PHP $version"
exit 1 Write-Error "Error" -ErrorAction Stop
} }
if($version -lt "5.5") { if($version -lt "5.5") {
('libeay32.dll', 'ssleay32.dll') | ForEach-Object -Parallel { Get-File -Url "$using:php_builder/releases/download/openssl-1.0.2u/$_" -OutFile $using:php_dir\$_ >$null 2>&1 } ('libeay32.dll', 'ssleay32.dll') | ForEach-Object -Parallel { Get-File -Url "$using:php_builder/releases/download/openssl-1.0.2u/$_" -OutFile $using:php_dir\$_ >$null 2>&1 }