Skip to content

New-CommandHelp throws error when using strict mode #800

@pewill

Description

@pewill

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

I default to strict mode and noticed that New-CommandHelp does not work with that configuration.
Repro steps:

function Get-Foo {'foo'}
Set-StrictMode -Version Latest
Get-Command Get-Foo | New-CommandHelp # this fails

Expected behavior

`New-CommandHelp` should work in strict mode or the limitation should be documented. The workaround to disable strict mode is straightforward, but it took me some time to figure out it was the culprit.

Actual behavior

It fails with error:

New-CommandHelp: The property 'relatedLinks' cannot be found on this object. Verify that the property exists.

Error details

Exception             :
    Type        : System.Management.Automation.PropertyNotFoundException
    ErrorRecord :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : The property 'relatedLinks' cannot be found on this object. Verify that the property exists.
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : PropertyNotFoundStrict
    TargetSite  :
        Name          : GetAdaptedValue
        DeclaringType : [System.Management.Automation.Language.PSGetMemberBinder]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message     : The property 'relatedLinks' cannot be found on this object. Verify that the property exists.
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  :
   at System.Management.Automation.Language.PSGetMemberBinder.GetAdaptedValue(Object obj, String member)
   at CallSite.Target(Closure, CallSite, Object)
   at Microsoft.PowerShell.PlatyPS.TransformBase.GetRelatedLinks(Object helpItem)
   at Microsoft.PowerShell.PlatyPS.TransformBase.ConvertCmdletInfo(CommandInfo commandInfo)
   at Microsoft.PowerShell.PlatyPS.TransformCommand.Transform(CommandInfo command)
   at Microsoft.PowerShell.PlatyPS.TransformCommand.Transform(IEnumerable`1 command)
   at Microsoft.PowerShell.PlatyPS.NewCommandHelpCommand.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo          : NotSpecified: (:) [New-CommandHelp], PropertyNotFoundException
FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.PlatyPS.NewCommandHelpCommand
InvocationInfo        :
    MyCommand        : New-CommandHelp
    ScriptLineNumber : 1
    OffsetInLine     : 23
    HistoryId        : 4
    Line             : Get-Command Get-Foo | New-CommandHelp
    Statement        : New-CommandHelp
    PositionMessage  : At line:1 char:23
                       + Get-Command Get-Foo | New-CommandHelp
                       +                       ~~~~~~~~~~~~~~~
    InvocationName   : New-CommandHelp
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

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

Version

1.0.1

Visuals

No response

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions