event-driven-dotnet / EventDriven.CQRS.Abstractions

Abstractions for implementing Command Query Responsibility Segregation in .NET.
4 stars 1 forks source link

Exceptions inside constructing ICommandHandler are lost #1

Open KlemenZarn2024 opened 3 weeks ago

KlemenZarn2024 commented 3 weeks ago

Describe the bug Problem occurs when there is an exception inside constructor of class implementing ICommandHandler interface. This exception is then lost and not present in the 'Errors' property of CommandResult object but instead some generic error is shown.

Expected behavior A correct exception should be either thrown (would be the best) or returned to the caller inside CommandResult object ('Errors' property).

To Reproduce Implement simple command handler class which will implement ICommandHandler and inside construtor throw new exception.

Screenshots Exception: image Resulting object: image Error message which is generic and can't help dev team to identify the original exception: image

Additional context The problem is very problematic because when this occurs dev team is not able to identify root cause why call to CQRS is failing. There is no exception thrown and even if some exception is present inside CommandResult then this exception is completly different from the one that was thrown originally. I would suggest that original exception is rather thrown than returned as a property inside CommandResult object.

tonysneed commented 3 weeks ago

Thanks for this. To stick with the pattern of populating the result's Error's property, we'll need to set it according to the error which is thrown.

I'll create a PR which includes a failing test to replicate the behavior.