Azure / Azure/azure-functions-powershell-worker
Set $ErrorActionPreference to Stop in PowerShell function templates code
- Dominant language
- C#
- Stars
- 215
- Forks
- 61
- Avg merge
- 21h 4m
- Merged PRs (30d)
- 6
Description
**Problem**
By PowerShell design, the default value of `$ErrorActionPreference` is `'Continue'`. New PowerShell users who are not familiar with the concept of non-terminating errors often get confused by the result: the PowerShell function execution seems to be completed successfully but has not in fact performed what it was supposed to perform, and the only way to notice this is to look at the logs.
This problem occasionally affects even experienced PowerShell users, and it seems to be a frequent annoyance for beginners, so it is worth mitigating. At the same time, we don't want to surprise experienced PowerShell users with by modifying the default behavior or introducing any other breaking changes, and we want to avoid creating Functions-specific abstractions on top of PowerShell.
**Proposal**
When a new PowerShell function is added from a template, the auto-generated code should include the following:
``` PowerShell
# By default, stop on any error
# (for more details, see )
$ErrorActionPreference = 'Stop'
```
As a result, this will make users aware of the difference between terminating vs. non-terminating errors, invite them to learn more if interested, and set a more intuitively expected behavior. At the same time, users familiar with PowerShell who insist on any different behavior will have an opportunity to review, change, or delete this code.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.