Skip to content

Error middleware enhancement #770

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using WorkflowCore.Models;

namespace WorkflowCore.Interface
{
Expand All @@ -11,8 +12,9 @@ public interface IWorkflowMiddlewareErrorHandler
/// <summary>
/// Asynchronously handle the given exception.
/// </summary>
/// <param name="workflowInstance">Workflow instance where error happened</param>
/// <param name="ex">The exception to handle</param>
/// <returns>A task that completes when handling is done.</returns>
Task HandleAsync(Exception ex);
Task HandleAsync(WorkflowInstance workflowInstance, Exception ex);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we make this backward compatible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielgerlag I can introduce something like IWorkflowMiddlewareErrorHandlerV2 that will have an old and a new method. And update the usages. However, I don't like this approach. What do you think?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using WorkflowCore.Interface;
using WorkflowCore.Models;

namespace WorkflowCore.Services
{
Expand All @@ -21,11 +22,12 @@ public DefaultWorkflowMiddlewareErrorHandler(ILogger<DefaultWorkflowMiddlewareEr
/// <summary>
/// Asynchronously handle the given exception.
/// </summary>
/// <param name="workflowInstance">Workflow instance where error happened</param>
/// <param name="ex">The exception to handle</param>
/// <returns>A task that completes when handling is done.</returns>
public Task HandleAsync(Exception ex)
public Task HandleAsync(WorkflowInstance workflowInstance, Exception ex)
{
_log.LogError(ex, "An error occurred running workflow middleware: {Message}", ex.Message);
_log.LogError(ex, "An error occurred running workflow '{workflow}' middleware: {Message}", workflowInstance.Id, ex.Message);
return Task.CompletedTask;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/WorkflowCore/Services/WorkflowMiddlewareRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task RunPostMiddleware(WorkflowInstance workflow, WorkflowDefinitio
var typeInstance = scope.ServiceProvider.GetService(errorHandlerType);
if (typeInstance != null && typeInstance is IWorkflowMiddlewareErrorHandler handler)
{
await handler.HandleAsync(exception);
await handler.HandleAsync(workflow, exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private static Expression<Func<Task>> HandleMethodFor(IWorkflowMiddleware middle
A<WorkflowDelegate>._);

private static Expression<Func<Task>> HandleMethodFor(IWorkflowMiddlewareErrorHandler errorHandler) =>
() => errorHandler.HandleAsync(A<Exception>._);
() => errorHandler.HandleAsync(A<WorkflowInstance>._, A<Exception>._);

public interface IDefLevelErrorHandler : IWorkflowMiddlewareErrorHandler
{
Expand Down