You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a rule for The Try statement is missing its Catch or Finally block.:
Invoke-ScriptAnalyzer-ScriptDefinition {function Test { Try { write-verbose'Test' } }}.ToString()
ParserError:
Line |1| … criptDefinition {function Test { Try { write-verbose'Test' } }}.ToSt …
| ~
| The Try statement is missing its Catch or Finally block.
But there is no rule for the opposite: a Catch (or Finally) statement that is missing its Try block:
Invoke-ScriptAnalyzer-ScriptDefinition {function Test { Catch { write-verbose'Test' } }}.ToString()
Even it produces a syntax error during run time (as it assumes it is a cmdlet, which is definitely not a recommend function name):
Catch { write-verbose'Test' }
Catch: The term 'Catch' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
The text was updated successfully, but these errors were encountered:
If you look at the first output, there is no rule, PSSA just passes the parser error back.
PSSA generally relies on parser and if parser cannot tell whether this is a command or catch block with no try block, then life will be hard because there must be a reason, which is likely PowerShell's generic nature that one could write a function called catch that accepts a scriptblock
If you look at the first output, there is no rule, PSSA just passes the parser error back.
Right, I missed that.
there must be a reason, which is likely PowerShell's generic nature that one could write a function called catch that accepts a scriptblock
Apart from the fact that this probably concerns a mistake (that actually happend in our environment), it concerns a reserved word which cannot be used as identifiers because they have a special meaning in PowerShell.
I did an additional rule request for this, see: #2099
There is a rule for The Try statement is missing its Catch or Finally block.:
But there is no rule for the opposite: a
Catch
(orFinally
) statement that is missing itsTry
block:Even it produces a syntax error during run time (as it assumes it is a cmdlet, which is definitely not a recommend function name):
The text was updated successfully, but these errors were encountered: