Handle non-AbortError errors in ErrorMiddleware - #4126
Open
MsfPablo wants to merge 2 commits into
Open
Conversation
Errors that don't conform to AbortError escaped ErrorMiddleware and were turned into a raw, unlogged 500 by Vapor's default error handling. That makes intermittent failures invisible in the application logs and causes swift-docc-render to display 'An unknown error occurred' rather than a useful message. Catch all errors, log them, and serve the standard HTML error page. Refs SwiftPackageIndex#3944
Member
|
Thanks for the PR, @MsfPablo ! We have a few high priority PRs that we need to take of at the moment but we'll be looking at this as soon as possible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3944
Problem
ErrorMiddlewareonly catchesAbortErrors. Any other error thrown from a route escapes the middleware, is converted into a raw 500 by Vapor's internal error handling, and is never logged by the application — so intermittent failures leave no trace.This also explains the "An unknown error occurred" pages reported in #3944: swift-docc-render shows "page not found" for a 404 on a
/data/…jsonrequest, but "An unknown error occurred" for any other error status. An unlogged raw 500 from a non-AbortErrorproduces exactly that, with nothing in the logs to diagnose it.(Credit to @DePasqualeOrg, who tracked this down in #3944 (comment).)
Change
ErrorMiddlewarenow catches every error, not justAbortError. Non-AbortErrors are treated as.internalServerError, logged atcriticalwith the underlying error description, and rendered with the usual HTML error page.AbortErrors with a status below 400 keep propagating, as before.The user-facing page only shows the generic "500 - Internal Server Error" text — the underlying error description goes to the log, not the response.
Notes
swift buildpasses locally. I couldn't run the test suite here (the toolchain in my environment can't resolve theTestingmodule for the test targets, which also fails on a clean checkout), so the added test is only verified by inspection — please let CI have the final word.