Skip to content

Missing try{} block not reported as a problem #1700

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

Open
bytepl opened this issue Jul 22, 2021 · 1 comment
Open

Missing try{} block not reported as a problem #1700

bytepl opened this issue Jul 22, 2021 · 1 comment

Comments

@bytepl
Copy link

bytepl commented Jul 22, 2021

Steps to reproduce

Write-Output "Test"
catch {
    Continue
}

save it as a file, then run Invoke-ScriptAnalyzer against it.

Expected behavior

An error should be displayed, saying that there's no 'try' block, just 'catch'.

Actual behavior

No error is returned and the script throws an error when executed.

catch : The term 'catch' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a p
 again.
At C:\Users\mchojnac\Desktop\test.ps1:2 char:1
+ catch {
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (catch:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1023
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1023
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.19.1
@ghost ghost added the Needs: Triage 🔍 label Jul 22, 2021
@rjmholt
Copy link
Contributor

rjmholt commented Aug 3, 2021

This is a fairly strange one — I'm not sure how many people are accidentally using just a catch block. And by itself, catch is a valid command name.

With that said, it might be useful to warn about commands that could also be keywords. That could also solve #1571.

However, given we don't know there's much demand for this and that we're not working on feature requests like this currently, I'll mark this issue as up-for-grabs.

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

2 participants