question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invoke-Formatter not working correctly for small scriptblocks

See original GitHub issue

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce

Invoke-Formatter -ScriptDefinition '{ $_.Status.IsCompleted -eq $true }'
Invoke-Formatter -ScriptDefinition '{ $null -ne $_.Status }'

Expected behavior

No error.

Actual behavior

Error

Invoke-Formatter : Object reference not set to an instance of an object.
At line:1 char:1
+ Invoke-Formatter -ScriptDefinition '{ $null -ne $_.Status }; '
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
    + FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.19041.1
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1
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.0
1.19.1
1.19.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
PrzemyslawKlyscommented, Sep 4, 2020
writeErrorStream      : True
PSMessageDetails      : 
Exception             : System.NullReferenceException: Object reference not set to an instance of an object.
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.IsPreviousTokenOnSameLine(LinkedListNode`
                        1 lparen)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.<FindInnerBraceViolations>d__49.MoveNext(
                        )
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Enumerable.<ConcatIterator>d__59`1.MoveNext()
                           at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
                           at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.UseConsistentWhitespace.AnalyzeScript(Ast ast, String fileName)
                           at Microsoft.Windows.PowerShell.ScriptAnalyzer.ScriptAnalyzer.<>c__DisplayClass83_1.<AnalyzeSyntaxTree>b__2()
TargetObject          :
CategoryInfo          : InvalidOperation: (:) [Invoke-Formatter], NullReferenceException
FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeFormatterCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
1reaction
PrzemyslawKlyscommented, Sep 4, 2020

It doesn’t matter

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Invoke-Command with Variables in ScriptBlock
Invoke-Command : Cannot validate argument on parameter 'ScriptBlock'. The argument is null. Provide a valid value for the argument, and then try ...
Read more >
about Script Blocks - PowerShell
In the PowerShell programming language, a script block is a collection of statements or expressions that can be used as a single unit....
Read more >
The PowerShell Best Practices and Style Guide
Like English spelling and grammar rules, PowerShell programming best practices and style rules nearly always have exceptions, but we are documenting a ...
Read more >
Untitled
Script commands names Classic SysAdmin: Writing a Simple Bash Script WebbCurrently, the last echo command does not print itself, only its output is ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found