Description
Describe 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).