Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce presence of '$ErrorActionPreference = "Stop"' #1271

Open
chriskuech opened this issue Jun 22, 2019 · 3 comments
Open

Enforce presence of '$ErrorActionPreference = "Stop"' #1271

chriskuech opened this issue Jun 22, 2019 · 3 comments

Comments

@chriskuech
Copy link

Summary of the new feature

Defensive Programming is essential to software engineering. To enable fail-fast methodology in PowerShell, you must add $ErrorActionPreference = "Stop" to the top of every PowerShell file. One can easily forget to add this line; I would like a PSScriptAnalyzer rule that enforces the presence of $ErrorActionPreference = "Stop", or at a minimum enforces explicitly setting $ErororActionPreference.

What is the latest version of PSScriptAnalyzer at the point of writing
N/A (whatever comes in the latest version of VS Code PowerShell extension)

@KirkMunro
Copy link
Contributor

Related: PowerShell/PowerShell-RFC#199.

@Jaykul
Copy link

Jaykul commented Jun 24, 2019

There are multiple types of errors in PowerShell, this would require people to throw away soft errors in favor of trying to turn everything into an exception. That might be appropriate in some places, but it's certainly not necessary in every file.

Nothing wrong with you having a rule like that for your own projects if you feel strongly about it, but it's not a rule we'd want to push on the whole community.

That is to say: you're welcome to argue that non-exception/non-terminating errors aren't useful (discussions related to that come up frequently in the PowerShell/PowerShell/issues), but if the PowerShell team is arguing the error design is right, you shouldn't ask the PSScriptAnalyzer team to say it's wrong.

@chriskuech
Copy link
Author

@Jaykul , I completely agree that this should not be enabled by default, but it nonetheless would be immensely valuable as an optional rule that can be installed with Install-Module PSScriptAnalyzer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants