diff --git a/src/System.Management.Automation/engine/Attributes.cs b/src/System.Management.Automation/engine/Attributes.cs index fbf200571a6..5ac315d2ae5 100644 --- a/src/System.Management.Automation/engine/Attributes.cs +++ b/src/System.Management.Automation/engine/Attributes.cs @@ -686,7 +686,7 @@ public string HelpMessage { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException("HelpMessage"); } _helpMessage = value; } @@ -707,7 +707,7 @@ public string HelpMessageBaseName { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException("HelpMessageBaseName"); } _helpMessageBaseName = value; } @@ -728,7 +728,7 @@ public string HelpMessageResourceId { if (string.IsNullOrEmpty(value)) { - throw PSTraceSource.NewArgumentException("value"); + throw PSTraceSource.NewArgumentException("HelpMessageResourceId"); } _helpMessageResourceId = value; } diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 5f1df94c2c0..5ee174bc14b 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -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: diff --git a/test/powershell/engine/Attributes.Tests.ps1 b/test/powershell/engine/Attributes.Tests.ps1 new file mode 100644 index 00000000000..4e000c898e3 --- /dev/null +++ b/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 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" + } +}