StartAutomating / ugit

Updated Git: A powerful PowerShell wrapper for git that lets you extend git, automate multiple repos, and output git as objects.
https://ugit.start-automating.com
MIT License
72 stars 6 forks source link

Importing Causes `Get-FormatData` to raise Unable to cast `Format.ControlReference` to `Format.ComplexControlBody` #41

Closed ninmonkey closed 2 years ago

ninmonkey commented 2 years ago

About

image

After importing ugit you are unable to call Get-FormatData without errors.

To Reproduce

[InvalidCastException] Short Version Top

Pwsh7> pwsh -Nop

Pwsh7> 
$mod = 'bitstransfer'
Remove-Module $mod
$A1 = Get-FormatData
Import-Module $mod -Force

$B1 = Get-FormatData
$diff1 = Compare-Object $A1 $B1

$mod = 'ugit'
Remove-Module $mod
$A1 = Get-FormatData
Import-Module $mod -Force

$B1 = Get-FormatData
$diff1 = Compare-Object $A1 $B1

$mod = 'bitstransfer'
Remove-Module $mod
$A1 = Get-FormatData
Import-Module $mod -Force

$B1 = Get-FormatData
$diff1 = Compare-Object $A1 $B1

[InvalidCastException] Full Version Top

Summary (Click to Expand) +70 Lines ```ps1 Import-Module $mod -Force $B = Get-FormatData $diff1 = Compare-Object $A $B ... 🠯 Click to Expand +70 lines 🠯 ... ``` Click to Expand 🠯 ```ps1 ... 🠯 Continued From Above 🠯 ... Pwsh7> pwsh -Nop ## ---- Pwsh7> $mod = 'ugit' $mod = 'bitstransfer' "Module: $mod" if (Get-Module -ea Ignore -Name $Mod) { Remove-Module $mod } $A = Get-FormatData Import-Module $mod -Force $B = Get-FormatData $diff1 = Compare-Object $A $B ## ---- Pwsh7> $mod = 'ugit' $mod = 'bitstransfer' "Module: $mod" if (Get-Module -ea Ignore -Name $Mod) { Remove-Module $mod } $A = Get-FormatData Import-Module $mod -Force $B = Get-FormatData $diff1 = Compare-Object $A $B ## ---- Pwsh7> $mod = 'ugit' #$mod = 'bitstransfer' "Module: $mod" if (Get-Module -ea Ignore -Name $Mod) { Remove-Module $mod } $A = Get-FormatData Import-Module $mod -Force $B = Get-FormatData $diff1 = Compare-Object $A $B ## ---- Pwsh7> $mod = 'ugit' $mod = 'bitstransfer' "Module: $mod" if (Get-Module -ea Ignore -Name $Mod) { Remove-Module $mod } $A = Get-FormatData Import-Module $mod -Force $B = Get-FormatData $diff1 = Compare-Object $A $B ```

Log [InvalidCastException] Top

Top

Error Log (Click to Expand +90 Lines) ```ps1 $Regex = @{ StripColor = '\u001B.*?m' StripAll = '\u001B.*?\p{L}' } $error | Get-Error | out-string -w 180 | %{ $_ -replace $Regex.StripAll, '' } | Set-Clipboard ``` ```yml PositionMessage : At line:12 char:6 + $B = Get-FormatData + ~~~~~~~~~~~~~~ InvocationName : Get-FormatData CommandOrigin : Internal ... ``` Click to Expand 🠯 ```yml Exception : Type : System.InvalidCastException TargetSite : Name : ChkCast_Helper DeclaringType : System.Runtime.CompilerServices.CastHelpers, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e MemberType : Method Module : System.Private.CoreLib.dll Message : Unable to cast object of type 'Microsoft.PowerShell.Commands.Internal.Format.ControlReference' to type 'Microsoft.PowerShell.Commands.Internal.Format.ComplexControlBody'. Source : System.Private.CoreLib HResult : -2147467262 StackTrace : at System.Management.Automation.CustomItemBase.Create(FormatToken token) at System.Management.Automation.CustomControlEntry..ctor(ComplexControlEntryDefinition entry) at System.Management.Automation.CustomControl..ctor(ComplexControlBody body, ViewDefinition viewDefinition) at Microsoft.PowerShell.Commands.GetFormatDataCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() CategoryInfo : NotSpecified: (:) [Get-FormatData], InvalidCastException FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetFormatDataCommand InvocationInfo : MyCommand : Get-FormatData ScriptLineNumber : 12 OffsetInLine : 6 HistoryId : 17 Line : $B = Get-FormatData PositionMessage : At line:12 char:6 + $B = Get-FormatData + ~~~~~~~~~~~~~~ InvocationName : Get-FormatData CommandOrigin : Internal ScriptStackTrace : at , : line 12 Exception : Type : System.InvalidCastException TargetSite : Name : ChkCast_Helper DeclaringType : System.Runtime.CompilerServices.CastHelpers, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e MemberType : Method Module : System.Private.CoreLib.dll Message : Unable to cast object of type 'Microsoft.PowerShell.Commands.Internal.Format.ControlReference' to type 'Microsoft.PowerShell.Commands.Internal.Format.ComplexControlBody'. Source : System.Private.CoreLib HResult : -2147467262 StackTrace : at System.Management.Automation.CustomItemBase.Create(FormatToken token) at System.Management.Automation.CustomControlEntry..ctor(ComplexControlEntryDefinition entry) at System.Management.Automation.CustomControl..ctor(ComplexControlBody body, ViewDefinition viewDefinition) at Microsoft.PowerShell.Commands.GetFormatDataCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() CategoryInfo : NotSpecified: (:) [Get-FormatData], InvalidCastException FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetFormatDataCommand InvocationInfo : MyCommand : Get-FormatData ScriptLineNumber : 9 OffsetInLine : 6 HistoryId : 17 Line : $A = Get-FormatData PositionMessage : At line:9 char:6 + $A = Get-FormatData + ~~~~~~~~~~~~~~ InvocationName : Get-FormatData CommandOrigin : Internal ScriptStackTrace : at , : line 9 Exception : Type : System.InvalidCastException TargetSite : Name : ChkCast_Helper DeclaringType : System.Runtime.CompilerServices.CastHelpers, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e MemberType : Method Module : System.Private.CoreLib.dll Message : Unable to cast object of type 'Microsoft.PowerShell.Commands.Internal.Format.ControlReference' to type 'Microsoft.PowerShell.Commands.Internal.Format.ComplexControlBody'. Source : System.Private.CoreLib HResult : -2147467262 StackTrace : at System.Management.Automation.CustomItemBase.Create(FormatToken token) at System.Management.Automation.CustomControlEntry..ctor(ComplexControlEntryDefinition entry) at System.Management.Automation.CustomControl..ctor(ComplexControlBody body, ViewDefinition viewDefinition) at Microsoft.PowerShell.Commands.GetFormatDataCommand.ProcessRecord() at System.Management.Automation.CommandProcessor.ProcessRecord() CategoryInfo : NotSpecified: (:) [Get-FormatData], InvalidCastException FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetFormatDataCommand InvocationInfo : MyCommand : Get-FormatData ScriptLineNumber : 12 OffsetInLine : 6 HistoryId : 16 Line : $B = Get-FormatData PositionMessage : At line:12 char:6 + $B = Get-FormatData + ~~~~~~~~~~~~~~ InvocationName : Get-FormatData CommandOrigin : Internal ScriptStackTrace : at , : line 12 ```

Top

StartAutomating commented 2 years ago

While I would love to be able to fix this issue, it is in fact an issue with Get-FormatData's inability to properly handle complex formatting (and thus is out of my control)