-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the bug
Instead of an error page, I'm getting a blank page (no HTML even, just text) with the content:
TypeError: Cannot read properties of undefined (reading 'replace') at escape_html (eval at runInlinedModule (file:///C:/Users/.../node_modules/vite/dist/node/module-runner.js:1062:11), :55:26) at static_error_page (eval at runInlinedModule (file:///C:/Users/.../node_modules/vite/dist/node/module-runner.js:1062:11), :46:94) at handle_fatal_error (eval at runInlinedModule (file:///C:/Users/.../node_modules/vite/dist/node/module-runner.js:1062:11), :68:10) at async respond (eval at runInlinedModule (file:///C:/Users/.../node_modules/vite/dist/node/module-runner.js:1062:11), :336:12) at async file:///C:/Users/.../node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:540:22
I've looked a bit into the functions from the stacktrace and it seems like this function is the problem:
kit/packages/kit/src/runtime/server/utils.js
Lines 99 to 116 in 217fc24
export async function handle_error_and_jsonify(event, options, error) { | |
if (error instanceof HttpError) { | |
return error.body; | |
} | |
if (__SVELTEKIT_DEV__ && typeof error == 'object') { | |
fix_stack_trace(error); | |
} | |
const status = get_status(error); | |
const message = get_message(error); | |
return ( | |
(await with_event(event, () => | |
options.hooks.handleError({ error, event, status, message }) | |
)) ?? { message } | |
); | |
} |
It promises to return an object that always has a string message
property, but in case of an HttpError
(first if statement in the function), this is not true. The error is defined by App.Error
, which is user-arbitrary.
Reproduction
Throw error(400, { code: 123 })
in the handle
hook. This is allowed by TypeScript if using custom error using something like this in app.d.ts
:
declare namespace App {
// ...
interface Error {
code: number
message?: string
}
}
Severity
annoyance