$ErrorActionPreference
noun
say it: “ER-er AK-shun PREF-er-ens” /ˈɛrɚ ˈækʃən ˈprɛfərəns/
A PowerShell setting that decides what every command does when it hits an error, such as carrying on or stopping the script at once.
What does $ErrorActionPreference do?
$ErrorActionPreference sets what every command does when it hits an error, so you don't add -ErrorAction to each one. Its default, Continue, prints the error and carries on. A build script sets it to 'Stop' at the top, so a missing folder stops the build instead of leaving it half done.
$ErrorActionPreference = 'Stop'
Copy-Item -Path src -Destination dist -Recurse # no src folder: the script stops here
Write-Output 'Built the site' # never reached
In a sentence
- “Sam put $ErrorActionPreference near the top of build.ps1, under the param block.”
- “Setting $ErrorActionPreference to 'Stop' made the build halt when the src folder was missing.”
Level: Journeyman · More PowerShell terms at this level
Updated