Azure / azure-functions-durable-extension

Durable Task Framework extension for Azure Functions
MIT License
711 stars 263 forks source link

TaskFailedException.FailureDetails.ErrorMessage loses text after the first line #2784

Open milkyware opened 2 months ago

milkyware commented 2 months ago

Description

When an exception is thrown in an Activity which has a message containing multiple lines which is then thrown as a TaskFailedException in an orchestration, only the first line of the message is available in FailureDetails.ErrorMessage

Expected behavior

All lines of the exception message are retained in TaskFailedException.FailureDetails.ErrorMessage

Actual behavior

Only the first line of the message is available in TaskFailedException.FailureDetails.ErrorMessage

Relevant source code snippets

[Function(nameof(OrchRun))]
public async Task OrchRun([OrchestrationTrigger] TaskOrchestrationContext context)
{
    try
    {
        await context.CallActivityAsync(nameof(ActivityRun));
    }
    catch (TaskFailedException ex)
    {
        Console.WriteLine(ex.FailureDetails.ErrorMessage);
    }
}

[Function(nameof(ActivityRun))]
public void ActivityRun([ActivityTrigger] TaskActivityContext context)
{
    throw new InvalidOperationException($"Now you see me{Environment.NewLine}Now you dont");
}

Known workarounds

Enabling user code exceptions in the worker seems to include the extra lines in the message, however, the side effect of this is that the FailureDetails.ErrorType of the exception is (unknown) similar to #2697.

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.Configure<WorkerOptions>(configure =>
        {
            configure.EnableUserCodeException = true;
        });
    }).Build()

App Details

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.1.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
  </ItemGroup>