diff --git a/host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs b/host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs index af0a5c43f..55b088487 100644 --- a/host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs +++ b/host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs @@ -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; } @@ -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 @@ -136,6 +148,7 @@ private static WorkerInitResponse BuildWorkerInitResponse() { Result = new StatusResult { Status = StatusResult.Types.Status.Success } }; + response.Capabilities[WorkerCapabilities.EnableUserCodeException] = bool.TrueString; return response; } diff --git a/host/src/FunctionsNetHost/Grpc/WorkerCapabilities.cs b/host/src/FunctionsNetHost/Grpc/WorkerCapabilities.cs new file mode 100644 index 000000000..749788fc2 --- /dev/null +++ b/host/src/FunctionsNetHost/Grpc/WorkerCapabilities.cs @@ -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"; + } +} diff --git a/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec b/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec index 36c3591a6..0f198f5a2 100644 --- a/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec +++ b/host/tools/build/Microsoft.Azure.Functions.DotnetIsolatedNativeHost.nuspec @@ -4,7 +4,7 @@ Microsoft.Azure.Functions.DotNetIsolatedNativeHost Microsoft Azure Functions dotnet-isolated native host dotnet-isolated azure-functions azure - 1.0.1 + 1.0.2 Microsoft Microsoft https://github.com/Azure/azure-functions-dotnet-worker