Thrown exceptions from __layout.svelte load result in plain text error responses
See original GitHub issueDescribe the bug
Throwing an exception (or returning a rejecting promise) from a load
function should be equivalent to returning { status: 500, error }
(apart from the former also resulting in a call to the handleError
hook). However, currently, it results in a plain text error message response from the server, which should be returned only when the __error.svelte
component fails to render.
Reproduction
Starting from the demo app, add this to __layout.svelte
:
<script context="module">
export function load() {
throw new Error("FOO");
}
</script>
Navigate to any page.
Logs
No response
System Info
System:
OS: Linux 5.10 Ubuntu 20.04.3 LTS (Focal Fossa)
CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
Memory: 6.36 GB / 12.32 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Yarn: 1.22.15
npm: 8.1.4
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.4
@sveltejs/kit: next => 1.0.0-next.202
svelte: ^3.44.0 => 3.44.3
Severity
serious, but I can work around it
Additional Information
This is inconvenient because I’d like to use the handleError
hook as the sole place for performing certain kinds of error logging, but I’d also prefer to not return a plain text error response to users. This means that currently my __layout.svelte
’s load
function needs to catch the error and reimplement the handleError
handling in a different way (since it has access to load
arguments instead of to the request
object).
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (13 by maintainers)
It’s now possible to
(group)
your roots and put the root+error.svelte
outside the group……which mostly solves this issue. That said, there are always going to be cases where we need to bail out to something (e.g. the
+error.svelte
can’t render because it referencesdata.undefined.something
).Right now, that’s a plain text response. I think we should make that a more appealing HTML page — something very basic, but nicer than what we currently have — and allow people to create a
src/error.html
page that overrides it, allowing you to at least render a branded page with a ‘visit our Twitter page for updates’ or whatever.Unlike
+error.svelte
, we can guarantee thatsrc/error.html
can be rendered without errors.Changing the plain text error response to HTML would be a breaking change, so I’ve added the label.
🤷 I mention in the “Additional Information” section specifically why I’m looking for this behavior. I currently have to duplicate some
handleError
hook logging logic in the__layout
load
.