Skip to content

Empty string in HelpMessage parameter causes stopping error with unhelpful message #4331

@ViperTG

Description

@ViperTG

Description

I found this error today when having problems getting a newly created script to work, and the error message was not helping. It refers to the #requires statement being formatted incorrectly but the script didn't even have the word "requires" anywhere in it. Turned out to be the HelpMessage parameter in one of the parameters that was empty as i had forgot to write something there.

Seems like it is a parsing error of some kind, not expecting the HelpMessage string to be empty.

In the documentation for HelpMessage it does not state that it cannot be empty.

Error was found on Win7 x64 running Windows Powershell 5.1
Tested on Windows 10 (15063) with Windows Powershell 5.1 and Powershell Core 6.0.0-Beta.4

Steps to reproduce

Take a simple script like this, call it Test-HelpMessage.ps1

[CmdletBinding()]
Param (
[Parameter(HelpMessage="")]
[String]$Parameter1
)
Write-Output "Hello"

Run the script .\Test-HelpMessage

Expected behavior

Expect to see "Hello" text as output.

Actual behavior

PS C:\temp> .\Test-HelpMessage.ps1
.\Test-HelpMessage.ps1 : Cannot process the #requires statement because it is not in the correct format.
The #requires statement must be in one of the following formats:
"#requires -shellid "
"#requires -version <major.minor>"
"#requires -psedition "
"#requires -pssnapin [-version <major.minor>]"
"#requires -modules "
"#requires -runasadministrator"
At line:1 char:1

  • .\Test-HelpMessage.ps1
  •   + CategoryInfo          : ObjectNotFound: (Test-HelpMessage.ps1:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : ScriptRequiresInvalidFormat
    
    
    

Suggestion [3,General]: The command Test-HelpMessage.ps1 was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\Test-HelpMessage.ps1". See "get-help about_Command_Precedence" for more details.

Content of $error[0].Exception.InnerException:
Cannot process argument because the value of argument "value" is not valid. Change the value of the "value" argument and run the operation again.

Environment data

$PSVersionTable

Name Value


PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.4
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions