question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad error message when `load` returns falsy from layout

See original GitHub issue

Describe the bug When returning nothing in a load function (as perceived to be permitted by the docs ) an error is thrown that doesn’t pin point the actual issue - which may not even need to be one - which is that I wrote return; at the end of the load function instead of return {};

Logs Cannot read property ‘error’ of undefined TypeError: Cannot read property ‘error’ of undefined at normalize (node_modules/@sveltejs/kit/dist/ssr.js:517:13) at load_node (node_modules/@sveltejs/kit/dist/ssr.js:829:11) at async respond_with_error (node_modules/@sveltejs/kit/dist/ssr.js:904:17) at async respond$1 (node_modules/@sveltejs/kit/dist/ssr.js:1119:13) at async render_page (node_modules/@sveltejs/kit/dist/ssr.js:1186:20) at async render (node_modules/@sveltejs/kit/dist/ssr.js:1537:10) at async Object.handle (/src/hooks:26:19) at async respond (node_modules/@sveltejs/kit/dist/ssr.js:1510:10) at async Immediate.<anonymous> (node_modules/@sveltejs/kit/dist/chunks/index.js:3305:23)

To Reproduce in any @type {import('@sveltejs/kit').Load} function, change current return value to return;

Expected behavior To set default object with status 200

Information about your SvelteKit Installation:

Diagnostics System: OS: macOS 11.3.1 CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz Memory: 172.27 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node npm: 7.12.1 - ~/.nvm/versions/node/v14.15.4/bin/npm Browsers: Chrome: 90.0.4430.212 Firefox: 87.0 Safari: 14.1 npmPackages: @sveltejs/kit: next => 1.0.0-next.107 svelte: ^3.34.0 => 3.38.2

Severity Not severe, easily fixable.

Additional context If this is by design, perhaps the docs could be updated to reflect this? With it currently saying that all keys are optional you’d assume you wouldn’t have to pass an empty object to an all optional object but rather nothing at all.

Thanks for all the hard work!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
benmccanncommented, Jul 23, 2021

The error message for this is dramatically better now. I think it got updated when I turned on strict typing for TypeScript in the most recent releases. Now it says:

Error: /src/routes/__layout.svelte - load must return a value except for page fall through

The main issue remaining here is that it just shows it on a blank page instead of the normal error page:

https://github.com/sveltejs/kit/blob/2a1e9795ad9773e04669a7b9d0234caa0b688ade/packages/kit/src/runtime/server/page/load_node.js#L269

But I guess that happens because since this error is on a layout page it occurs on the error page and so since the error page can’t be rendered it just shows a blank page with the error. I don’t have any ideas how to do that differently, so am going to call this one solved

1reaction
Conduitrycommented, May 14, 2021

Ah I see. I think this is probably a bug, yeah, but I’ll let Rich weigh in. For route fallthrough purposes, I can’t see a reason why you’d want different behavior when returning falsy from a layout load.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The cause of "bad magic number" error when loading a ...
This error indicates you are trying to load a non-valid file type into R. For some reason, R no longer recognizes this file...
Read more >
Error handling - Apollo GraphQL Docs
The below example returns a user-friendly message whenever Apollo Server throws a GRAPHQL_VALIDATION_FAILED error: TypeScript.
Read more >
What went wrong? Troubleshooting JavaScript - MDN Web Docs
The error message says "guessSubmit.addeventListener is not a function", which means that the function we're calling is not recognized by the ...
Read more >
Write error messages for your UI with validate - R Shiny
An R expression that returns TRUE or FALSE . A character string. Shiny will display this string as a validation error message if...
Read more >
Troubleshoot Google Docs, Sheets, Slides & Forms error ...
If you get an error message such as "Something went wrong. Reload" or "Unable to load file" preventing you from making edits on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found