Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-FormatData should output non-terminating errors #21139

Open
5 tasks done
StartAutomating opened this issue Jan 24, 2024 · 3 comments · May be fixed by #21157
Open
5 tasks done

Get-FormatData should output non-terminating errors #21139

StartAutomating opened this issue Jan 24, 2024 · 3 comments · May be fixed by #21157
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@StartAutomating
Copy link

StartAutomating commented Jan 24, 2024

Prerequisites

Steps to reproduce

Get-FormatData # Works fine for now

this will demonstrate the bug, but so will any module that has a element in a format file.

Install-Module Posh -Scope CurrentUser

Import-Module Posh

Get-FormatData # Now just blows up unhelpfully

Expected behavior

Get-FormatData writes a non-terminating error for each formatter with errors.

Actual behavior

Get-FormatData: Unable to cast object of type 'Microsoft.PowerShell.Commands.Internal.Format.ControlReference' to type 'Microsoft.PowerShell.Commands.Internal.Format.ComplexControlBody'.

Error details

Exception             : 
    Type       : System.InvalidCastException
    TargetSite : 
        Name          : ChkCast_Helper
        DeclaringType : System.Runtime.CompilerServices.CastHelpers, System.Private.CoreLib, Version=8.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 : 1
    OffsetInLine     : 1
    HistoryId        : 42
    Line             : Get-Formatdata
    Statement        : Get-Formatdata
    PositionMessage  : At line:1 char:1
                       + Get-Formatdata
                       + ~~~~~~~~~~~~~~
    InvocationName   : Get-Formatdata
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

@StartAutomating StartAutomating added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jan 24, 2024
@mklement0

This comment was marked as resolved.

@mklement0

This comment was marked as resolved.

@StartAutomating StartAutomating changed the title Get-FormatData should output non-terminating errors when failing to load a control Get-FormatData should output non-terminating errors Jan 25, 2024
@SteveL-MSFT
Copy link
Member

Isn't the real problem here that the error is too internal and doesn't help inform the user which formatdata is at fault?

@SteveL-MSFT SteveL-MSFT linked a pull request Jan 29, 2024 that will close this issue
22 tasks
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR Indicates that a PR is out for the issue label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants