Skip to content

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

Merged
merged 8 commits into from
Apr 2, 2019

Conversation

davidfowl
Copy link
Member

  • 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

Contributes to #8536

- 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
@davidfowl davidfowl requested a review from rynowak April 1, 2019 02:13
public DeveloperExceptionPageMiddleware(
RequestDelegate next,
IOptions<DeveloperExceptionPageOptions> options,
ILoggerFactory loggerFactory,
IWebHostEnvironment hostingEnvironment,
DiagnosticSource diagnosticSource)
DiagnosticSource diagnosticSource,
IEnumerable<IDeveloperPageExceptionFilter> filters)
Copy link
Member

Choose a reason for hiding this comment

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

breaking change yo

Copy link
Member Author

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>
Copy link
Member

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

{
var nextFilter = _exceptionHandler;
_exceptionHandler = (context, exception) => filter.HandleExceptionAsync(context, exception, nextFilter);
}
Copy link
Member

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

@@ -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) { }
Copy link
Member Author

@davidfowl davidfowl Apr 1, 2019

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)

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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 👼

Copy link
Member

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.

{
var compilationException = ex as ICompilationException;
var compilationException = errorContext.Exception as ICompilationException;
Copy link
Member

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.

Copy link
Member Author

@davidfowl davidfowl Apr 1, 2019

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.

Copy link
Member

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.

Copy link
Member Author

@davidfowl davidfowl Apr 1, 2019

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.

Copy link
Contributor

@Eilon Eilon left a 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.

@davidfowl davidfowl marked this pull request as ready for review April 2, 2019 04:00
@davidfowl davidfowl requested a review from analogrelay as a code owner April 2, 2019 04:00
@analogrelay analogrelay added this to the 3.0.0-preview4 milestone Apr 2, 2019
@davidfowl davidfowl merged commit f4c61de into master Apr 2, 2019
@JamesNK JamesNK added the breaking-change This issue / pr will introduce a breaking change, when resolved / merged. label Apr 5, 2019
@davidfowl davidfowl deleted the davidfowl/error-page-filters branch April 15, 2019 07:48
@amcasey amcasey added the area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares breaking-change This issue / pr will introduce a breaking change, when resolved / merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants