-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Set IExceptionHandlerFeature on DeveloperExceptionPageMiddleware #52688
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for your PR, @Kahbazi. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
src/Middleware/Diagnostics/src/DeveloperExceptionPage/DeveloperExceptionPageMiddlewareImpl.cs
Outdated
Show resolved
Hide resolved
// Arrange | ||
using var host = new HostBuilder() | ||
.ConfigureWebHost(webHostBuilder => | ||
{ | ||
webHostBuilder | ||
.UseTestServer() | ||
.Configure(app => | ||
{ | ||
app.Use(async (context, next) => | ||
{ | ||
await next(); | ||
|
||
var exceptionHandlerFeature = context.Features.GetRequiredFeature<IExceptionHandlerPathFeature>(); | ||
|
||
Assert.NotNull(exceptionHandlerFeature); | ||
Assert.Equal("Test exception", exceptionHandlerFeature.Error.Message); | ||
Assert.Equal(context.Request.Path, exceptionHandlerFeature.Path); | ||
}); | ||
app.UseExceptionHandler(exceptionApp => | ||
{ | ||
exceptionApp.Run(context => Task.CompletedTask); | ||
}); | ||
app.Run(context => | ||
{ | ||
throw new Exception("Test exception"); | ||
}); | ||
|
||
}); | ||
}).Build(); | ||
|
||
await host.StartAsync(); | ||
|
||
var server = host.GetTestServer(); | ||
var request = new HttpRequestMessage(HttpMethod.Get, "/path"); | ||
|
||
var response = await server.CreateClient().SendAsync(request); |
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 test isn't forcing the asserts to run. Move asserts into the main path of the test:
// Arrange | |
using var host = new HostBuilder() | |
.ConfigureWebHost(webHostBuilder => | |
{ | |
webHostBuilder | |
.UseTestServer() | |
.Configure(app => | |
{ | |
app.Use(async (context, next) => | |
{ | |
await next(); | |
var exceptionHandlerFeature = context.Features.GetRequiredFeature<IExceptionHandlerPathFeature>(); | |
Assert.NotNull(exceptionHandlerFeature); | |
Assert.Equal("Test exception", exceptionHandlerFeature.Error.Message); | |
Assert.Equal(context.Request.Path, exceptionHandlerFeature.Path); | |
}); | |
app.UseExceptionHandler(exceptionApp => | |
{ | |
exceptionApp.Run(context => Task.CompletedTask); | |
}); | |
app.Run(context => | |
{ | |
throw new Exception("Test exception"); | |
}); | |
}); | |
}).Build(); | |
await host.StartAsync(); | |
var server = host.GetTestServer(); | |
var request = new HttpRequestMessage(HttpMethod.Get, "/path"); | |
var response = await server.CreateClient().SendAsync(request); | |
// Arrange | |
var tcs = new TaskCompletionSource<IExceptionHandlerPathFeature>(TaskCreationOptions.RunContinuationsAsynchronously); | |
using var host = new HostBuilder() | |
.ConfigureWebHost(webHostBuilder => | |
{ | |
webHostBuilder | |
.UseTestServer() | |
.Configure(app => | |
{ | |
app.Use(async (context, next) => | |
{ | |
await next(); | |
var exceptionHandlerFeature = context.Features.GetRequiredFeature<IExceptionHandlerPathFeature>(); | |
tcs.SetResult(exceptionHandlerFeature); | |
}); | |
app.UseExceptionHandler(exceptionApp => | |
{ | |
exceptionApp.Run(context => Task.CompletedTask); | |
}); | |
app.Run(context => | |
{ | |
throw new Exception("Test exception"); | |
}); | |
}); | |
}).Build(); | |
await host.StartAsync(); | |
var server = host.GetTestServer(); | |
var request = new HttpRequestMessage(HttpMethod.Get, "/path"); | |
var response = await server.CreateClient().SendAsync(request); | |
var feature = await tcs.Task; | |
Assert.NotNull(feature); | |
Assert.Equal("Test exception", feature.Error.Message); | |
Assert.Equal(context.Request.Path, feature.Path); |
(note: changed in a text field, not might not compile, and/or have bugs)
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
@Kahbazi Are you still interested in working on this? |
@adityamandaleeka Sorry I missed this PR, I will work on it this weekend. |
Fixes #49195