dahlbyk / posh-git

A PowerShell environment for Git
http://dahlbyk.github.io/posh-git/
MIT License
7.7k stars 801 forks source link

Null Reference Exception in PoshGitVcsPrompt #713

Open smitcham opened 5 years ago

smitcham commented 5 years ago

System Details

Issue Description

When I got to a repository that isn't clean on status, I'm getting a null ref exception

` VERBOSE: 00092:Getting status VERBOSE: 00195:Parsing status VERBOSE: 00205:Status: ## master...origin/master VERBOSE: 00219:Status: ?? Feature.MySQL.UnitTests/app.config [Error: You cannot call a method on a null-valued expression. VERBOSE: PoshGitVcsPrompt error details:

PSMessageDetails : Exception : System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) TargetObject : CategoryInfo : InvalidOperation: (:) [], RuntimeException FullyQualifiedErrorId : InvokeMethodOnNull ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at Get-GitStatus, C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\GitUtils.ps1: line 256 at <ScriptBlock>, C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\GitPrompt.ps1: line 330 at <ScriptBlock>, C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\GitPrompt.ps1: line 324 at Global:Write-VcsStatus, C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\GitPrompt.ps1: line 324 at <ScriptBlock>, C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\posh-git.psm1: line 56 at <ScriptBlock>, <No file>: line 1 PipelineIterationInfo : {}

I haven't been able to track down what is exactly null at this point, the $filesAdded list exists, the $matches is filled in, and the $matches['path1] expression seems to have data. Not really familiar with writing powershell scripts though.

smitcham commented 5 years ago

As an additional note, this doesn't occur in the ISE environment and does not occur in the PowerShellCore 6.0 environment.

rkeithhill commented 4 years ago

You are right in that the only way I can see getting that error is if $filesAdded were null but I'm not sure how that could be. What does this return in your Windows PowerShell 5 console where you see this error:

$null -eq (New-Object System.Collections.Generic.List[string])

I would expect $false. That is what I get but if for some reason this returns $true for you, then we'd have something more to go on.

dahlbyk commented 4 years ago

Is this still an issue?