Skip to content
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

Added more constructors to CircuitBreaker Exceptions to set inner exc… #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mansoor-omrani
Copy link

When the task employed in CircuitBreakerInvoker.Invoke() for executing given action fails and its Status is IsFaulted, we need to pass task.Exception to the new CircuitBreaker exception we want to throw so that it is set in its InnerException. Otherwise we will lose the real exception and the user who used CircuitBreaker will not know what the source of failure was.

…eption.

Passed task.Exception for Faulted tasks in CircuitBreakerInvoker.Invoke() method  to throwing CircuitBreaker exception instance.
@alexandrnikitin
Copy link
Owner

@mansoor-omrani Thank you for the PR. I'm not sure I understand the intention. The Task.Wait method rethrows an exception thrown during the execution of the task. The inner exception should contain the exception. Here're tests that cover the use case.

public class InvokeThroughTests : CircuitBreakerInvokerTests

Can you please share your use case? Or maybe even a test that covers it.

@alexandrnikitin
Copy link
Owner

I reviewed your recent changes. I'm still not sure that I get it. CircuitBreakerOpenException is meant to indicate that the circuit is open. CircuitBreaker.Execute throws an exception if execution fails so you can handle it in your code. Why do you want to wrap it into CircuitBreakerOpenException?

@mansoor-omrani
Copy link
Author

@alexandrnikitin Hi alex. The requirement for the change I made was to embed the potential exception that occurs in user's given action in the CircuitBreaker exception (in its InnerException).

Currently CircuitBreaker exceptions don't bring out exceptions that happen in user's action. The InnerException is null.

You can check that with the following test:

[Fact]
public void ExepectInnerExceptionWhenActionFails()
{
   var state = Substitute.For<ICircuitBreakerState>();
   var e = Assert.ThrowsAny<Exception>(() => _sut.InvokeThrough(state, () => { throw new ArgumentNullException(); }, TimeSpan.FromMilliseconds(100)));
   state.Received().InvocationFails();
   Assert.IsType<ArgumentNullException>(e.InnerException);
}

But I noticed other problems with the Invoke() and InvokeAsync() as well.

I'm working on the code. I try to explain them in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants