Azure/SFNuGet

New-ServiceFabricNugetPackage: function is closing the console

Closed this issue · 3 comments

When 'New-ServiceFabricNuGetPackage' is missing parameters the function is closing the console by calling "exit 1" and writing the error-message to the host but not the error-output.
Happy debugging....

Ways to improve this:

  • Use the param-section to force that values are provided
  • Write-Errors to the error-output and not "write-host"
  • DO NOT CALL "Exit" to exit a powershell-script. If you realy want to exit your function then "return" or use a combination of $errorActionPreference and "write-error" but DO NOT KILL THE CALLER

SFNuGetModule.psm1: i changed lines 28 to 44 to this:

[cmdletbinding()]
    param(
        [parameter(mandatory=$true)][string] $InputPath,
        [parameter(mandatory=$true)][string] $OutPath,
        [switch] $Publish=$false
    )
$ErrorActionPreference = "stop"

#check if InputPath exists
if (!(Test-Path $InputPath)) {
    Write-error "Input path is not found."
}

Makes sense. This is my first PowerShell project so I appreciate any tips to make it higher quality. Do you want to create a pull request for your changes?

I have made the changes and opened a pull-request and wrote what i have changed and why.