Push-OutputBinding Should Throw Exceptions at Script Scope
Tried pushing an output binding to a table today, and it errored with the following:
7/19/2019 7:05:13 PM] Executed 'Functions.SendGrid' (Failed, Id=f7995877-67db-4af4-80dc-6a9390a35bba)
[7/19/2019 7:05:13 PM] System.Private.CoreLib: Exception while executing function: Functions.SendGrid. Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:. Microsoft.Azure.WebJobs.Extensions.Storage: 0:The specified entity already exists.
RequestId:c1db00fc-0588-48c8-a395-7a45739ff0cf
Time:2019-07-19T19:05:13.3671345Z (HTTP status code 409: EntityAlreadyExists. 0:The specified entity already exists.
RequestId:c1db00fc-0588-48c8-a395-7a45739ff0cf
Time:2019-07-19T19:05:13.3671345Z). Microsoft.WindowsAzure.Storage: 0:The specified entity already exists.
RequestId:c1db00fc-0588-48c8-a395-7a45739ff0cf
Time:2019-07-19T19:05:13.3671345Z.
Unfortunately I can't try/catch or trap{} it, so my script just dies. As a workaround I just fetch a table object directly, but I shouldn't have to, I should be able to follow the output binding pattern and practice, but be able to handle any issues that might crop up.
#Get an Azure Table
#Adapted from https://docs.microsoft.com/en-us/azure/cosmos-db/tutorial-develop-table-dotnet
using namespace Microsoft.Azure.Cosmos.Table
function Get-AzFunctionTable ([String]$FunctionTableName = $TriggerMetaData.FunctionName) {
#requires -module Az.Storage
$FunctionStorageAccount = [CloudStorageAccount]::Parse($env:AzureWebJobsStorage)
$FunctionTableClient = [CloudStorageAccountExtensions]::CreateCloudTableClient($FunctionStorageAccount)
$FunctionTable = $FunctionTableClient.GetTableReference($FunctionTableName)
if ($FunctionTable.CreateIfNotExists()) {Write-Output "Table $($functiontableclient.baseuri)/$($FunctionTableName) did not exist so it was created."}
if ($FunctionTable) {
return $FunctionTable
} else {
write-error "There was a problem fetching the Azure Function Table"
}
}
So this is not possible currently because there's no way to communicate with the worker while the operation is still ongoing, output bindings are all sent at once after the function is completed.
https://github.com/Azure/azure-functions-powershell-worker/blob/d08886b93a109b26e079a90c11bfe8f29d813321/src/RequestProcessor.cs#L446-L478
Hence this is blocking on the worker protocol having a proactive outputbinding RPC function. I created an issue for this and this issue will be blocking on this being completed. https://github.com/Azure/azure-functions-language-worker-protobuf/issues/47
Is there any progress on this? It's impossible to implement proper HTTP error codes for functions without this being fixed. As there is also no functionality to choose an insert mode for table storage, it's impossible to return e.g. a 409 when the entity already exists.
@itpropro theres an upstream dependency here that has to be implemented: https://github.com/Azure/azure-functions-language-worker-protobuf/issues/47
I saw no comments on my request so I assume it's not a priority.