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

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

Closed
ViperTG opened this issue Jul 24, 2017 · 1 comment
Assignees
Labels
Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime

Comments

@ViperTG
Copy link

ViperTG commented Jul 24, 2017

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

@SteveL-MSFT SteveL-MSFT added WG-Engine core PowerShell engine, interpreter, and runtime Review - Committee The PR/Issue needs a review from the PowerShell Committee and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Jul 24, 2017
@SteveL-MSFT SteveL-MSFT self-assigned this Jul 24, 2017
@SteveL-MSFT
Copy link
Member

@ViperTG I don't think we should allow for an empty string, the current code actually checks against that. However, we should have a better error message. Got fix, working on test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Fixed The issue is fixed. WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

3 participants