-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Tighten up error handling #11287
Comments
For me, this is key. In the future, HandleServerError should "always" be called and support something like this (in pseudo-code)
Benefits of this is:
|
So you're saying that |
But in all modesty, the API today is not really that well designed. Ask 10 Sveltekit developers how it works today, and I think you get 5 different answers. Example:
If developers are not bothered with their errors being reported, or implementing a custom shape in What is really the downside to always going through Imagine a future where the docs about error handling simply is:
But I could be missing something here? |
I've opened #11295 to revert the recent changes (sorry @alexbjorlig). I agree that the current design isn't quite right, and we should take the opportunity of 2.0 to revisit it. Here's what I think should happen: If you want to log expected errors too, that's easy enough — just replace |
@Rich-Harris ok, I understand. It makes sense to think hard about the right design. With the impressive work done by the Sveltekit team, I'm sure we will get a good solution in 2.0. I'm here to offer my help writing tests, to cover these cases that we often find in our production Sveltekit app (mostly related to form actions). Comments/questions about the 2.0 error designI agree it's a good mental model to think about errors as being "unexpected" or "expected". But it is equally important to identify the HTTP error code; to help determine if this error should be reported to Sentry or not. That was also my motivation for my 2 PRs - to solve the problem that "expected" errors were reported as "unexpected" errors. Just one more comment:
This is exactly what Sveltekit developers are already doing today - we are "forced" to identify the severity by identifying |
see #11289, which addresses all these points |
The PR looks amazing - and it even includes the 2 tests 🤩 Can't wait for 2.0 now |
Describe the problem
#11278 sent me down a rabbit hole of error handling once more. It occured to me that us throwing
error
s is not correct, strictly speaking. Someone could've enhanced theApp.Error
object which means that more properties than justmessage
are required, and as such callingerror
with just a string is wrong.Describe the proposed solution
Instead of using
error
, we distinguish between unforseen fatal errors and not-so-bad errors by expanding on what was introduced in #11131:NonFatalError
withstatus
andmessage
(andNotFound
introduced in that PR would go away)handleError
is called with those, too, but our fallback uses themessage
verbatim in that case (because we know it doesn't contain sensitive information)@sveltejs/kit
so people can doinstanceof NonFatalError
inhandleError
and inspect the status/message (would also make More information about error in HandleServerError #6774 more clear)/not send this to an error reporting service in that caseNonFatalError
is discovered, thestatus
is not500
but instead the one defined in the instanceAlternatives considered
Leave this as is and document this somewhere in the code base
Importance
would make my life easier
Additional Information
Putting this on the 2.0 milestone because if we change this it could be seen as a breaking change (things appearing in
handleError
differently)The text was updated successfully, but these errors were encountered: