Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add ExceptionHandled to ExceptionContext #4825

Merged
merged 1 commit into from
Jun 9, 2016

Conversation

ryanbrandenburg
Copy link
Contributor

Fixes #4700.

@rynowak please check me extra well since I'm not sure I correctly interpreted the behavior/functionality of this area.

@rynowak
Copy link
Member

rynowak commented Jun 8, 2016

please check me extra well since I'm not sure I correctly interpreted the behavior/functionality of this area.

hint: I'd suggest first investigating MVC5's behavior. We found that we were missing this from the API surface of previous versions.

@@ -69,6 +69,11 @@ public virtual ExceptionDispatchInfo ExceptionDispatchInfo
}

/// <summary>
/// Gets or sets an indication that the <see cref="Exception"/> has been handled.
/// </summary>
public virtual bool ExceptionHandled { get; set; } = false;
Copy link
Member

Choose a reason for hiding this comment

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

Why virtual? I don't think there's an easy way to replace the exception context with your own, and being get set I don't see how making it virtual would improve unit testing which is the other scenario I would consider. @rynowak am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

All of the properties on all of these classes are virtual for mocking support

@ryanbrandenburg
Copy link
Contributor Author

@rynowak after reviewing how we did this in MVC5 I've made an update. I believe this would be a breaking change for any exception filters that currently handle exceptions as they'd need to start marking ExceptionHandled as true.

@rynowak
Copy link
Member

rynowak commented Jun 8, 2016

Do you want to explain what the delta in behavior is and why this is terrifying you? I need some deets.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/ExceptionHandled branch from 90fa7c6 to d57f2d0 Compare June 8, 2016 23:19
@ryanbrandenburg
Copy link
Contributor Author

🆙📅

The major change from RC2 here (other than just adding the property) is that we set ExceptionHandled to true when handling an exception, rather than nulling the exception. This is consistent with the behavior I observed in MVC5. One thing that has me a bit confused is that yesterday in person I thought I remembered you saying that user code wouldn't be handling this interaction (previously nulling .Exception, now setting .ExceptionHandled true) but if we look at https://github.com/aspnet/Mvc/blob/dev/test/WebSites/FiltersWebSite/Filters/ShortCircuitExceptionFilter.cs it seems like use defined filters are the ONLY place where ExceptionHandled would get set. Am I mis-remembering that or missing something else here?

@@ -422,7 +422,7 @@ private Task InvokeAllExceptionFiltersAsync()

_diagnosticSource.AfterOnExceptionAsync(_exceptionContext, current.FilterAsync);

if (_exceptionContext.Exception == null)
if (_exceptionContext.ExceptionHandled)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this condition different from the other ones? Think what would happen if you set the .Exception to null. Would other exception filters run?

@rynowak
Copy link
Member

rynowak commented Jun 9, 2016

@ryanbrandenburg
Copy link
Contributor Author

🆙📅

.Setup(f => f.OnException(It.IsAny<ExceptionContext>()))
.Callback<ExceptionContext>(context =>
{
filter2.ToString();
Copy link
Member

Choose a reason for hiding this comment

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

These calls to ToString() aren't needed. This is an ancient workaround for an issue in Moq. Just don't put them in new code

@rynowak
Copy link
Member

rynowak commented Jun 9, 2016

:shipit: after removing those ToString()s

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/ExceptionHandled branch from 7262434 to 913a7eb Compare June 9, 2016 21:35
@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/ExceptionHandled branch from 913a7eb to 27bde12 Compare June 9, 2016 22:19
@ryanbrandenburg ryanbrandenburg merged commit 5339a3e into dev Jun 9, 2016
@ryanbrandenburg ryanbrandenburg deleted the rybrande/ExceptionHandled branch September 27, 2016 22:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants