PowerShell / PowerShell/platyPS
New-CommandHelp throws for commands with an .EXAMPLE but no .DESCRIPTION
Open
Beginner friendly
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 871
- Forks
- 166
- Avg merge
- 21h 17m
- Merged PRs (30d)
- 1
Description
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: https://github.com/alt3/Docusaurus.Powershell/issues/247
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in TransformBase.cs at the helpItem.description and helpItem.examples check, then run the PowerShell reproduction from the issue. Verify that a command with an .EXAMPLE but no .DESCRIPTION produces a CommandHelp object without throwing, and that processing a pipeline batch is not aborted by this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, powershell
- Domain
- documentation, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100