Improve error handling in afterInstall.ps1

Enhanced error reporting by checking if caught errors are System.Exception and printing the appropriate message. This provides clearer output for both exception and non-exception error types during file download, extraction, and main script execution.
This commit is contained in:
Namhyeon Go 2025-11-21 17:57:18 +09:00
parent 9b6fa4d233
commit 49ebde6835

View File

@ -69,7 +69,11 @@ function Download-File {
} }
catch { catch {
Write-Host "[ERROR] Failed to download: $Url" Write-Host "[ERROR] Failed to download: $Url"
Write-Host $_.Exception.Message if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
throw throw
} }
} }
@ -101,7 +105,11 @@ function Extract-CompressedFile {
} }
catch { catch {
Write-Host "[ERROR] Failed to extract: $CompressedPath" Write-Host "[ERROR] Failed to extract: $CompressedPath"
Write-Host $_.Exception.Message if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
throw throw
} }
@ -170,7 +178,11 @@ function Extract-TarGzArchive {
} }
catch { catch {
Write-Host "[ERROR] Failed to extract TAR.GZ archive: $ArchivePath" Write-Host "[ERROR] Failed to extract TAR.GZ archive: $ArchivePath"
Write-Host $_.Exception.Message if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
throw throw
} }
} }
@ -319,8 +331,12 @@ try {
} }
} }
catch { catch {
Write-Host "[FATAL] Download phase faled." Write-Host "[FATAL] Download phase failed."
Write-Host $_.Exception.Message if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
exit 1 exit 1
} }