Azure-Player / azure.datafactory.tools

Tools for deploying Data Factory (v2) in Microsoft Azure
https://azureplayer.net/adftools
MIT License
212 stars 69 forks source link

Catch InvalidOperation exception when reading empty FilterFilePath in New-AdfPublishOption.ps1 #338

Closed camilo-s closed 1 year ago

camilo-s commented 1 year ago

Describe the bug When parsing the content of the file at FilterFilePath, the function New-AdfPublishOption currently doesn't catch the exception that arises when the file is empty. In such case, calling New-AdfPublishOption -FilterFilePath ".\deployment\rules.txt" will fail at line 49 with an error message You cannot call a method on a null-valued expression. due to $FilterText being empty.

To provide a more contextual error message, I've tried catching this exception downstream like so:

try {
    $opt = New-AdfPublishOption -FilterFilePath ".\deployment\rules.txt"   
}
catch [System.ArgumentNullException] {
    Write-Host "Filter file empty: $FilterFilePath"
    throw
}

unsuccessfully.

I understand there is no point in passing an empty filter file, but we'd like to catch that edge case in our CI/CD pipeline regardless.

To Reproduce

  1. Add an empty file .\deployment\rules.txt
  2. Run $opt = New-AdfPublishOption -FilterFilePath ".\deployment\rules.txt"

Expected behaviour A proper typed exception is raised when the provided filter file is empty.

Screenshots n/a

Version of PowerShell module of:

Provide all files to reproduce the issue Screenshot 2023-06-29 at 08 52 44