-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Initial design for exception page filters #8958
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
Conversation
- This change introduces the concept of an IDeveloperPageException filter that runs whenever the developer exception page has encountered an error. It follows the middleware pattern (chain of resposibility) which allows short circuiting or decorating the default logic. - Added tests
src/Middleware/Diagnostics/src/DeveloperExceptionPage/IDeveloperPageExceptionFilter.cs
Outdated
Show resolved
Hide resolved
public DeveloperExceptionPageMiddleware( | ||
RequestDelegate next, | ||
IOptions<DeveloperExceptionPageOptions> options, | ||
ILoggerFactory loggerFactory, | ||
IWebHostEnvironment hostingEnvironment, | ||
DiagnosticSource diagnosticSource) | ||
DiagnosticSource diagnosticSource, | ||
IEnumerable<IDeveloperPageExceptionFilter> filters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaking change yo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know but it's 3.0 and I'm expecting this to be acceptable. I didn't update the refs tho because who ever remembers that the first time 😄
@@ -40,12 +41,14 @@ public class DeveloperExceptionPageMiddleware | |||
/// <param name="loggerFactory"></param> | |||
/// <param name="hostingEnvironment"></param> | |||
/// <param name="diagnosticSource"></param> | |||
/// <param name="filters"></param> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this are some hq docs
src/Middleware/Diagnostics/src/DeveloperExceptionPage/DeveloperExceptionPageMiddleware.cs
Show resolved
Hide resolved
{ | ||
var nextFilter = _exceptionHandler; | ||
_exceptionHandler = (context, exception) => filter.HandleExceptionAsync(context, exception, nextFilter); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the CoR is so elegant and cool
src/Middleware/Diagnostics/test/UnitTests/DeveloperExceptionPageMiddlewareTest.cs
Outdated
Show resolved
Hide resolved
@@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Diagnostics | |||
{ | |||
public partial class DeveloperExceptionPageMiddleware | |||
{ | |||
public DeveloperExceptionPageMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Builder.DeveloperExceptionPageOptions> options, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment, System.Diagnostics.DiagnosticSource diagnosticSource) { } | |||
public DeveloperExceptionPageMiddleware(Microsoft.AspNetCore.Http.RequestDelegate next, Microsoft.Extensions.Options.IOptions<Microsoft.AspNetCore.Builder.DeveloperExceptionPageOptions> options, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment, System.Diagnostics.DiagnosticSource diagnosticSource, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Diagnostics.IDeveloperPageExceptionFilter> filters) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change. If you want to revolt, tell me and I'll add an overload (https://github.com/aspnet/AspNetCore/pull/8958/files#r270702887)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really think there are many (any?) folks newing up this middleware class themselves? That said, generally speaking we should lean to remaining compatible for all changes unless we have good reason not to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really think there are many (any?) folks newing up this middleware class themselves?
No.
That said, generally speaking we should lean to remaining compatible for all changes unless we have good reason not to.
We may have to live with this one. Adding another constructor results in the system picking the "wrong" one. I think the risk is small enough to warrant it. I'm investigating anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the breaking change label 👼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It picks the first constructor it can satisfy, put the new one on top.
src/Middleware/Diagnostics/src/DeveloperExceptionPage/IDeveloperPageExceptionFilter.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics/src/DeveloperExceptionPage/IDeveloperPageExceptionFilter.cs
Outdated
Show resolved
Hide resolved
{ | ||
var compilationException = ex as ICompilationException; | ||
var compilationException = errorContext.Exception as ICompilationException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Factor out DisplayCompilationException as a filter? Even if you don't register it via DI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? It's just a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proof of concept. This is doing exactly what filters are designed to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it makes any sense. The thing left to resolve is the ordering concern that @rynowak brought up. The slight code will make the diff bigger and don't add any value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig the design.
Contributes to #8536