Closed nightroman closed 4 years ago
@nightroman Thanks for the feedback. Agreed, error messages could be improved to provide more helpful information.
Another problem with this example (I may submit a separate issue if you want me to). If I have other rule files in the same folder then they are not invoked due to this failure. E.g. if another file is named good.rule.ps1 then it is invoked, then test.rule.ps1 fails. But if another file is named zoo.rule.ps1 then it is not invoked. I would expect all rule files invoked and their outcomes reported.
Another problem with this example (I may submit a separate issue if you want me to). If I have other rule files in the same folder then they are not invoked due to this failure. E.g. if another file is named good.rule.ps1 then it is invoked, then test.rule.ps1 fails. But if another file is named zoo.rule.ps1 then it is not invoked. I would expect all rule files invoked and their outcomes reported.
Split to separate issue as this is a bug.
@nightroman There are some challenges with PowerShell overriding InvocationInfo on the ErrorRecord, however I think the following should address your feedback.
Windows PowerShell example:
TargetName: dd29ecf524b030a65261e3059c48ab9e1ecb2585
RuleName Outcome Recommendation
-------- ------- --------------
WithPass Pass Should pass
WithParseError Error Rule to generate a PowerShell parsing exception
invoke-psrule : WithParseError : Reported 'A parameter cannot be found that matches parameter name
'MisspelledParameter'.'. At C:\dev\workspace\PSRule\tests\PSRule.Tests\FromFileWithError.Rule.ps1:78 char:22
At line:1 char:6
+ '' | invoke-psrule .\tests\PSRule.Tests\FromFileWithError.Rule.ps1 -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (dd29ecf524b030a65261e3059c48ab9e1ecb2585:System.String) [Invoke-PSRule
], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand,WithParseError,Invok
e-PSRule
PowerShell 7 example:
TargetName: dd29ecf524b030a65261e3059c48ab9e1ecb2585
RuleName Outcome Recommendation
-------- ------- --------------
WithPass Pass Should pass
WithParseError Error Rule to generate a PowerShell parsing exception
Invoke-PSRule: WithParseError : Reported 'A parameter cannot be found that matches parameter name 'MisspelledParameter'.'. At C:\Dev\Workspace\PSRule\tests\PSRule.Tests\FromFileWithError.Rule.ps1:78 char:22
Example
Test.Rule.ps1
Actual result
Invoke-PSRule
fails with the following information:Note there is no references to the problem rule name, file, error source location.
Expected result
The failure information should mention at least the rule name and ideally the error location in the source file.
Environment
PSRule 0.21.0
$PSVersionTable