Skip to content

New-CommandHelp throws for commands with an .EXAMPLE but no .DESCRIPTION #857

Description

@bravo-kernel

Prerequisites

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

Steps to reproduce

@'
function Test-Broken {
    <#
        .SYNOPSIS
            A synopsis.
        .EXAMPLE
            Get-Something
    #>
    [CmdletBinding()] param()
}
'@ | Set-Content Broken.psm1

Import-Module ./Broken.psm1
New-CommandHelp -CommandInfo (Get-Command Test-Broken)

Expected behavior

A `CommandHelp` object is returned (with an empty description) — or, at worst, a per-command non-terminating error so the remaining commands in a pipeline batch still generate.

Actual behavior

`New-CommandHelp` throws. Adding a `.DESCRIPTION` makes it work. The error is statement-terminating, so one under-documented command loses the entire pipeline batch.

Error details

New-CommandHelp: The best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments


Root cause in `TransformBase.cs`:


if (string.IsNullOrEmpty(GetStringFromDescriptionArray(helpItem.description)) &&
    string.IsNullOrEmpty(helpItem.examples))


`helpItem.examples` is a PSObject (not a string) whenever examples exist, so the second operand throws — but only when the description is empty, because the `&&` short-circuits otherwise. That is why well-documented modules never see it.

Suggested fix: null-check `helpItem.examples` instead of `string.IsNullOrEmpty()`, and consider reporting a per-command non-terminating error so the remaining commands still generate.

Environment data

- Microsoft.PowerShell.PlatyPS 1.0.2
- PowerShell 7.5.8

Version

1.0.2

Visuals

No response

Additionally

Found while migrating Alt3.Docusaurus.Powershell to the v2 pipeline; downstream tracking: alt3/Docusaurus.Powershell#247

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions