diff --git a/src/code/PublishPSResource.cs b/src/code/PublishPSResource.cs index 21f3a2698..f20025b68 100644 --- a/src/code/PublishPSResource.cs +++ b/src/code/PublishPSResource.cs @@ -167,8 +167,8 @@ protected override void BeginProcessing() ThrowTerminatingError( new ErrorRecord( new ArgumentException( - "The path to the resource to publish is not in the correct format, point to a path or file of the module or script to publish."), - "InvalidSourcePath", + "The path to the resource to publish is not in the correct format or does not exist. Please provide the path of the root module or the path to the .psd1."), + "InvalidPublishPath", ErrorCategory.InvalidArgument, this)); } @@ -187,6 +187,15 @@ protected override void BeginProcessing() pathToScriptFileToPublish = resolvedPath; resourceType = ResourceType.Script; } + else { + ThrowTerminatingError( + new ErrorRecord( + new ArgumentException( + $"The publish path provided, '{resolvedPath}', is not a valid. Please provide a path to the root module or path to the .psd1."), + "InvalidPublishPath", + ErrorCategory.InvalidArgument, + this)); + } if (!String.IsNullOrEmpty(DestinationPath)) { @@ -578,7 +587,8 @@ private string CreateNuspec( } // defaults to false - string requireLicenseAcceptance = psData.ContainsKey("requirelicenseacceptance") ? psData["requirelicenseacceptance"].ToString() : "false"; + // boolean value needs to be a lowercase string for it to be correctly parsed + string requireLicenseAcceptance = psData.ContainsKey("requirelicenseacceptance") ? psData["requirelicenseacceptance"].ToString().ToLower() : "false"; metadataElementsDictionary.Add("requireLicenseAcceptance", requireLicenseAcceptance); diff --git a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 index 2df3c6c80..33594b23b 100644 --- a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 @@ -546,4 +546,12 @@ Describe "Test Publish-PSResource" -tags 'CI' { {Publish-PSResource -Path $incorrectdepmoduleversion -ErrorAction Stop} | Should -Throw -ErrorId "InvalidModuleManifest,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource" } + + It "Publish a module with using an invalid file path (path to .psm1), should throw" { + $fileName = "$script:PublishModuleName.psm1" + $psm1Path = Join-Path -Path $script:PublishModuleBase -ChildPath $fileName + $null = New-Item -Path $psm1Path -ItemType File -Force + + {Publish-PSResource -Path $psm1Path -Repository $testRepository2 -ErrorAction Stop} | Should -Throw -ErrorId "InvalidPublishPath,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource" + } } \ No newline at end of file