Skip to content

Commit

Permalink
Fix the missing Exception parameter in `IAsyncMessageErrorHandler[T…
Browse files Browse the repository at this point in the history
…Message, TMessageResult]` and `IAsyncMessageErrorHandler[TMessage]` interfaces.
  • Loading branch information
litenova committed Dec 23, 2023
1 parent 91f8a42 commit bc5f3a3
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 39 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v.0.23.0
- Fix the missing `Exception` parameter in `IAsyncMessageErrorHandler[TMessage, TMessageResult]` and `IAsyncMessageErrorHandler[TMessage]` interfaces.

## v.0.22.0
- Introduce tag-based handler filtering through `HandlerTag` and `HandlerTags` attributes.
- Add `CommandMediationSettings` to `ICommandMediator` to allow configuring command mediation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
#nullable enable

using System;
using System.Threading;
using System.Threading.Tasks;

namespace LiteBus.Messaging.Abstractions;

/// <summary>
/// Defines a contract for an asynchronous message error handler that operates on messages of type <typeparamref name="TMessage"/> and message results of type <typeparamref name="TMessageResult"/>.
/// Represents an asynchronous error handler for messages of type <typeparamref name="TMessage"/>
/// and results of type <typeparamref name="TMessageResult"/>.
/// This interface should be implemented to handle exceptions that occur during the processing of messages.
/// </summary>
/// <typeparam name="TMessage">The type of the message that this handler can process.</typeparam>
/// <typeparam name="TMessageResult">The type of the message result that this handler deals with.</typeparam>
/// <typeparam name="TMessage">The type of the message that this error handler is applicable to.</typeparam>
/// <typeparam name="TMessageResult">The type of the result produced by the message processing.</typeparam>
public interface IAsyncMessageErrorHandler<in TMessage, in TMessageResult> : IMessageErrorHandler<TMessage, TMessageResult>
{
/// <summary>
/// Synchronously handles an error occurring during message processing using the default error handling strategy, by internally calling the asynchronous <see cref="HandleErrorAsync(TMessage, TMessageResult, CancellationToken)"/> method.
/// Synchronously handles an error encountered in message processing by delegating to an asynchronous method.
/// </summary>
/// <param name="message">The message that was being processed when the error occurred.</param>
/// <param name="exception"></param>
/// <param name="messageResult">The result of the message processing that led to the error, of type <typeparamref name="TMessageResult"/>.</param>
/// <returns>The result of handling the error, potentially modified or enriched with additional information.</returns>
object IMessageErrorHandler<TMessage, TMessageResult>.HandleError(TMessage message, Exception exception, TMessageResult messageResult)
/// <param name="message">The message that encountered the error.</param>
/// <param name="exception">The exception that was thrown during message processing.</param>
/// <param name="messageResult">The result of the message processing prior to the error, which may be null.</param>
/// <returns>A placeholder object returned after handling the error.</returns>
object IMessageErrorHandler<TMessage, TMessageResult>.HandleError(TMessage message, Exception exception, TMessageResult? messageResult)
{
return HandleErrorAsync(message, messageResult, AmbientExecutionContext.Current?.CancellationToken ?? throw new NoExecutionContextException());
return HandleErrorAsync(message, messageResult, exception, AmbientExecutionContext.Current?.CancellationToken ?? throw new NoExecutionContextException());
}

/// <summary>
/// Asynchronously handles an error that occurred during the processing of a message, potentially altering the result based on the error handling logic implemented.
/// Asynchronously handles an error encountered in message processing.
/// </summary>
/// <param name="message">The message that was being processed when the error occurred, of type <typeparamref name="TMessage"/>.</param>
/// <param name="messageResult">The result of the message processing that led to the error, of type <typeparamref name="TMessageResult"/>.</param>
/// <param name="cancellationToken">A token to monitor for cancellation requests, allowing this method to be exited prematurely if necessary. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation, potentially altering the message result based on the error handling logic implemented.</returns>
Task HandleErrorAsync(TMessage message, TMessageResult messageResult, CancellationToken cancellationToken = default);
/// <param name="message">The message that encountered the error.</param>
/// <param name="messageResult">The result of the message processing prior to the error, which may be null.</param>
/// <param name="exception">The exception that was thrown during message processing.</param>
/// <param name="cancellationToken">A token for cancelling the error handling operation.</param>
/// <returns>A task representing the asynchronous error handling operation.</returns>
Task HandleErrorAsync(TMessage message, TMessageResult? messageResult, Exception exception, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
#nullable enable

using System;
using System.Threading;
using System.Threading.Tasks;

namespace LiteBus.Messaging.Abstractions;

/// <summary>
/// Defines a contract for an asynchronous message error handler that operates on messages of type <typeparamref name="TMessage"/>.
/// Represents an asynchronous error handler for messages of type <typeparamref name="TMessage"/>.
/// This interface should be implemented to handle exceptions that occur during message processing.
/// </summary>
/// <typeparam name="TMessage">The type of the message that this handler can process.</typeparam>
/// <typeparam name="TMessage">The type of the message that this error handler is applicable to.</typeparam>
public interface IAsyncMessageErrorHandler<in TMessage> : IMessageErrorHandler<TMessage, object>
{
/// <summary>
/// Synchronously handles an error occurring during message processing using the default error handling strategy, by internally calling the asynchronous <see cref="HandleErrorAsync(TMessage, CancellationToken)"/> method.
/// Synchronously handles an error encountered in message processing by delegating to an asynchronous method.
/// </summary>
/// <param name="message">The message that was being processed when the error occurred.</param>
/// <param name="exception"></param>
/// <param name="messageResult">The result of the message processing that led to the error, if any.</param>
/// <returns>The result of handling the error, potentially modified or enriched with additional information.</returns>
object IMessageErrorHandler<TMessage, object>.HandleError(TMessage message, Exception exception, object messageResult)
/// <param name="message">The message that encountered the error.</param>
/// <param name="exception">The exception that was thrown during message processing.</param>
/// <param name="messageResult">The result of the message processing prior to the error.</param>
/// <returns>A placeholder object returned after handling the error.</returns>
object IMessageErrorHandler<TMessage, object>.HandleError(TMessage message, Exception exception, object? messageResult)
{
return HandleErrorAsync(message, AmbientExecutionContext.Current?.CancellationToken ?? throw new NoExecutionContextException());
return HandleErrorAsync(message, messageResult, exception, AmbientExecutionContext.Current?.CancellationToken ?? throw new NoExecutionContextException());
}

/// <summary>
/// Asynchronously handles an error that occurred during the processing of a message.
/// Asynchronously handles an error encountered in message processing.
/// </summary>
/// <param name="message">The message that was being processed when the error occurred.</param>
/// <param name="cancellationToken">A token to monitor for cancellation requests, allowing this method to be exited prematurely if necessary. Defaults to <see cref="CancellationToken.None"/>.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task HandleErrorAsync(TMessage message, CancellationToken cancellationToken = default);
/// <param name="message">The message that encountered the error.</param>
/// <param name="messageResult">The result of the message processing prior to the error.</param>
/// <param name="exception">The exception that was thrown during message processing.</param>
/// <param name="cancellationToken">A token for cancelling the error handling operation.</param>
/// <returns>A task representing the asynchronous error handling operation.</returns>
Task HandleErrorAsync(TMessage message, object? messageResult, Exception exception, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Commands.UnitTests.UseCases;

public class GlobalCommandErrorHandler : ICommandErrorHandler
{
public Task HandleErrorAsync(ICommand message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ICommand message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
if (message is IAuditableCommand auditableCommand)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Commands.UnitTests.UseCases.ProblematicCommand;

public sealed class ProblematicCommandErrorHandler : ICommandErrorHandler<ProblematicCommand>
{
public Task HandleErrorAsync(ProblematicCommand message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicCommand message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Commands.UnitTests.UseCases.ProblematicCommand;

public sealed class ProblematicCommandErrorHandler2 : ICommandErrorHandler<ProblematicCommand>
{
public Task HandleErrorAsync(ProblematicCommand message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicCommand message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Events.UnitTests.UseCases;

public class GlobalEventErrorHandler : IEventErrorHandler
{
public Task HandleErrorAsync(IEvent message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(IEvent message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
if (message is IAuditableEvent auditableEvent)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Events.UnitTests.UseCases.ProblematicEvent;

public sealed class ProblematicEventErrorHandler : IEventErrorHandler<ProblematicEvent>
{
public Task HandleErrorAsync(ProblematicEvent message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicEvent message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Events.UnitTests.UseCases.ProblematicEvent;

public sealed class ProblematicEventErrorHandler2 : IEventErrorHandler<ProblematicEvent>
{
public Task HandleErrorAsync(ProblematicEvent message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicEvent message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Queries.UnitTests.UseCases;

public class GlobalQueryErrorHandler : IQueryErrorHandler
{
public Task HandleErrorAsync(IQuery message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(IQuery message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
if (message is IAuditableQuery auditableQuery)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Queries.UnitTests.UseCases.ProblematicQuery;

public sealed class ProblematicQueryErrorHandler : IQueryErrorHandler<ProblematicQuery>
{
public Task HandleErrorAsync(ProblematicQuery message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicQuery message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace LiteBus.Queries.UnitTests.UseCases.ProblematicQuery;

public sealed class ProblematicQueryErrorHandler2 : IQueryErrorHandler<ProblematicQuery>
{
public Task HandleErrorAsync(ProblematicQuery message, object messageResult, CancellationToken cancellationToken = default)
public Task HandleErrorAsync(ProblematicQuery message, object? messageResult, Exception exception, CancellationToken cancellationToken = default)
{
message.ExecutedTypes.Add(GetType());

Expand Down

0 comments on commit bc5f3a3

Please sign in to comment.