falldamagestudio / UE4-GHA-BuildSystem

Build UE4 games with GitHub + GitHub Actions + Google Cloud
MIT License
13 stars 8 forks source link

Errors during Packer build scripts should fail image build process #11

Closed Kalmalyzer closed 3 years ago

Kalmalyzer commented 3 years ago

Today, a failure within some of the Powershell logic will not fail the entire Packer build process (example: https://github.com/falldamagestudio/UE4-GHA-BuildSystem/runs/3041707680 ).

Any unhandled error thrown from the Powershell scripts should also make Packer abort with an error. The current behaviour just hides problems.

Kalmalyzer commented 3 years ago

There is a long reference on error handling and non-terminating errors vs terminating errors here: https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-exceptions

And another analysis, which points out that there's statement-terminating vs script-terminating, and that under remoting then terminating gets converted to non-terminating, here: https://github.com/MicrosoftDocs/PowerShell-Docs/issues/1583

In short, we need to do two things:

  1. Add -ErrorAction Stop to most cmdlet invocations. This will convert any of their internal Write-Error invocations from non-terminating into terminating errors. Those can then be caught by catch.
  2. Add a try { ... } catch { Write-Error $_; exit 1 } wrapper around each Powershell command invocation in the packer json file; this ensures that any terminating error will result in an exit code of 1. That, in turn, ensures that Packer interprets any error as the step having failed, and will stop & signal that the entire Packer job has failed.
Kalmalyzer commented 3 years ago

Solved in cc5fce5fcebfe30b1e8a84d368794e12419428f4.