Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix invalid value error message on some cmdlet attributes to point to…
… the specific attribute.

Removed wrapping of argument exception into not useful requires exception
  • Loading branch information
SteveL-MSFT committed Jul 24, 2017
commit 13f8a04dad54f2b4f2953696c287fd4149bb553d
6 changes: 3 additions & 3 deletions src/System.Management.Automation/engine/Attributes.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,6 @@ internal CommandProcessorBase LookupCommandProcessor(CommandInfo commandInfo,
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
Original file line number Diff line number Diff line change
@@ -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"
}
}