Skip to content

Commit

Permalink
- Sending EnableUserCodeException as a capability of native worker. (#…
Browse files Browse the repository at this point in the history
…1960)

- Improving the exception message for env reload failure.
- Version bump to 1.0.2
  • Loading branch information
kshyju authored Oct 12, 2023
1 parent a70ead9 commit fd86b66
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
39 changes: 26 additions & 13 deletions host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ private async Task Process(StreamingMessage msg)

if (workerConfig?.Description is null)
{
responseMessage.FunctionEnvironmentReloadResponse = BuildFailedEnvironmentReloadResponse(new FunctionAppPayloadNotFoundException());
Logger.LogTrace($"Could not find a worker config in {envReloadRequest.FunctionAppDirectory}");
responseMessage.FunctionEnvironmentReloadResponse = BuildFailedEnvironmentReloadResponse();
break;
}

// function app payload which uses an older version of Microsoft.Azure.Functions.Worker package does not support specialization.
if (!workerConfig.Description.CanUsePlaceholder)
{
Logger.LogTrace("App payload uses an older version of worker package which does not support specialization.");
responseMessage.FunctionEnvironmentReloadResponse = BuildFailedEnvironmentReloadResponse(new EnvironmentReloadNotSupportedException());
Logger.LogTrace("App payload uses an older version of Microsoft.Azure.Functions.Worker SDK which does not support placeholder.");
var e = new EnvironmentReloadNotSupportedException("This app is not using the latest version of Microsoft.Azure.Functions.Worker SDK and therefore does not leverage all performance optimizations. See https://aka.ms/azure-functions/dotnet/placeholders for more information.");
responseMessage.FunctionEnvironmentReloadResponse = BuildFailedEnvironmentReloadResponse(e);
break;
}

Expand Down Expand Up @@ -98,27 +100,37 @@ private async Task Process(StreamingMessage msg)
}
}

private static FunctionEnvironmentReloadResponse BuildFailedEnvironmentReloadResponse(Exception exception)
private static FunctionEnvironmentReloadResponse BuildFailedEnvironmentReloadResponse(Exception? exception = null)
{
var rpcException = new RpcException
{
Message = exception.ToString(),
Source = exception.Source ?? string.Empty,
StackTrace = exception.StackTrace ?? string.Empty
};

var response = new FunctionEnvironmentReloadResponse
{
Result = new StatusResult
{
Status = StatusResult.Types.Status.Failure,
Exception = rpcException
Status = StatusResult.Types.Status.Failure
}
};

response.Result.Exception = ToUserRpcException(exception);

return response;
}

internal static RpcException? ToUserRpcException(Exception? exception)
{
if (exception is null)
{
return null;
}

return new RpcException
{
Message = exception.Message,
Source = exception.Source ?? string.Empty,
StackTrace = exception.StackTrace ?? string.Empty,
Type = exception.GetType().FullName ?? string.Empty,
IsUserException = true
};
}
private static FunctionMetadataResponse BuildFunctionMetadataResponse()
{
var metadataResponse = new FunctionMetadataResponse
Expand All @@ -136,6 +148,7 @@ private static WorkerInitResponse BuildWorkerInitResponse()
{
Result = new StatusResult { Status = StatusResult.Types.Status.Success }
};
response.Capabilities[WorkerCapabilities.EnableUserCodeException] = bool.TrueString;

return response;
}
Expand Down
10 changes: 10 additions & 0 deletions host/src/FunctionsNetHost/Grpc/WorkerCapabilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace FunctionsNetHost.Grpc
{
internal static class WorkerCapabilities
{
internal const string EnableUserCodeException = "EnableUserCodeException";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<id>Microsoft.Azure.Functions.DotNetIsolatedNativeHost</id>
<title>Microsoft Azure Functions dotnet-isolated native host</title>
<tags>dotnet-isolated azure-functions azure</tags>
<version>1.0.1</version>
<version>1.0.2</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<projectUrl>https://github.com/Azure/azure-functions-dotnet-worker</projectUrl>
Expand Down

0 comments on commit fd86b66

Please sign in to comment.