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

Useful error message when HelpMessage attributes are empty string #4334

Merged
merged 1 commit into from Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/Attributes.cs
Expand Up @@ -686,7 +686,7 @@ public string HelpMessage
{
if (string.IsNullOrEmpty(value))
{
throw PSTraceSource.NewArgumentException("value");
throw PSTraceSource.NewArgumentException("HelpMessage");
}
_helpMessage = value;
}
Expand All @@ -707,7 +707,7 @@ public string HelpMessageBaseName
{
if (string.IsNullOrEmpty(value))
{
throw PSTraceSource.NewArgumentException("value");
throw PSTraceSource.NewArgumentException("HelpMessageBaseName");
}
_helpMessageBaseName = value;
}
Expand All @@ -728,7 +728,7 @@ public string HelpMessageResourceId
{
if (string.IsNullOrEmpty(value))
{
throw PSTraceSource.NewArgumentException("value");
throw PSTraceSource.NewArgumentException("HelpMessageResourceId");
}
_helpMessageResourceId = value;
}
Expand Down
10 changes: 0 additions & 10 deletions src/System.Management.Automation/engine/CommandDiscovery.cs
Expand Up @@ -775,16 +775,6 @@ private static string BuildPSSnapInDisplayName(PSSnapInSpecification PSSnapin)
new CommandNotFoundException(reqSyntaxException.Message, reqSyntaxException);
throw e;
}
catch (PSArgumentException argException)
{
CommandNotFoundException e =
new CommandNotFoundException(
commandInfo.Name,
argException,
"ScriptRequiresInvalidFormat",
DiscoveryExceptions.ScriptRequiresInvalidFormat);
throw e;
}
break;
case CommandTypes.Filter:
case CommandTypes.Function:
Expand Down
24 changes: 24 additions & 0 deletions test/powershell/engine/Attributes.Tests.ps1
@@ -0,0 +1,24 @@
Describe "Attribute tests" -Tags "CI" {
BeforeEach {
Remove-Item $testdrive/test.ps1 -Force -ErrorAction SilentlyContinue
}

It "<attribute> attribute returns argument error if empty" -TestCases @(
@{Attribute="HelpMessage"},
@{Attribute="HelpMessageBaseName"},
@{Attribute="HelpMessageResourceId"}
) {
param($attribute)

$script = @"
[CmdletBinding()]
Param (
[Parameter($attribute="")]
[String]`$Parameter1
)
Write-Output "Hello"
"@
New-Item -Path $testdrive/test.ps1 -Value $script -ItemType File
{ & $testdrive/test.ps1 } | ShouldBeErrorId "Argument"
}
}