Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push-OutputBinding Should Throw Exceptions at Script Scope #284

Open
JustinGrote opened this issue Jul 19, 2019 · 4 comments
Open

Push-OutputBinding Should Throw Exceptions at Script Scope #284

JustinGrote opened this issue Jul 19, 2019 · 4 comments
Assignees
Milestone

Comments

@JustinGrote
Copy link

JustinGrote commented Jul 19, 2019

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"
    }
}
@JustinGrote
Copy link
Author

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.

private static void BindOutputFromResult(InvocationResponse response, AzFunctionInfo functionInfo, IDictionary results)
{
if (functionInfo.DurableFunctionInfo.Type == DurableFunctionType.None) // TODO: but let activity functions have output bindings, too
{
// Set out binding data and return response to be sent back to host
foreach (var (bindingName, bindingInfo) in functionInfo.OutputBindings)
{
var outValue = results[bindingName];
var transformedValue = Utils.TransformOutBindingValueAsNeeded(bindingName, bindingInfo, outValue);
var dataToUse = transformedValue.ToTypedData();
// if one of the bindings is '$return' we need to set the ReturnValue
if (string.Equals(bindingName, AzFunctionInfo.DollarReturn, StringComparison.OrdinalIgnoreCase))
{
response.ReturnValue = dataToUse;
continue;
}
var paramBinding = new ParameterBinding()
{
Name = bindingName,
Data = dataToUse
};
response.OutputData.Add(paramBinding);
}
}
if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue)
{
response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData();
}
}

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.
Azure/azure-functions-language-worker-protobuf#47

@itpropro
Copy link

itpropro commented May 4, 2020

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.

@JustinGrote
Copy link
Author

@itpropro theres an upstream dependency here that has to be implemented: Azure/azure-functions-language-worker-protobuf#47

I saw no comments on my request so I assume it's not a priority.

@AnatoliB
Copy link
Contributor

AnatoliB commented Aug 19, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants