kit icon indicating copy to clipboard operation
kit copied to clipboard

feat: support throwing error in handle

Open ivanhofer opened this issue 2 years ago • 9 comments

Closes #7966 Heavily inspired by #7612; no new tests for the same reason described there.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • [x] This message body should clearly illustrate what problems it solves.
  • [ ] Ideally, include a test that fails without this PR but passes with it.

Tests

  • [x] Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

ivanhofer avatar Dec 14 '22 10:12 ivanhofer

@ivanhofer is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Dec 14 '22 10:12 vercel[bot]

⚠️ No Changeset found

Latest commit: 1fcd07f447167f207bcb85c70261f76e148fd3fc

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Dec 14 '22 10:12 changeset-bot[bot]

My git cli says I don't have any changes to pull. Not sure how to bring this branch up2date.

ivanhofer avatar Dec 14 '22 10:12 ivanhofer

did you pull from the master branch or your error-handle branch?

gtm-nayan avatar Dec 14 '22 10:12 gtm-nayan

did you pull from the master branch or your error-handle branch?

I pulled from master, and I also updated my fork to contain the latest changes from the original repo. Pulling directly from the original does not work either. Not sure what is broken.

ivanhofer avatar Dec 14 '22 11:12 ivanhofer

Tried a quick stab at this, it's trickier than I thought. Ideally we fall back to the static error page, but I'm not sure how to do that from a data response yet.

dummdidumm avatar Dec 14 '22 12:12 dummdidumm

Tried a quick stab at this, it's trickier than I thought. Ideally we fall back to the static error page, but I'm not sure how to do that from a data response yet.

Is the problem that it is a client-side navigation, the data request responds with json and can't be used to deliver the error page because it would be html? And we can't render the +error.svelte page because the hooks.server.js has no information about the rendering process because it never calls resolve(event)?

ivanhofer avatar Dec 14 '22 12:12 ivanhofer

We can't render +error.svelte because that included +layout.svelte, which might include a +layout.server.js, which means there's another handle call, which would yield the same error. Furthermore it would be inconsistent to show +error.svelte in the JS case an error.html in the SSR case.

dummdidumm avatar Dec 14 '22 13:12 dummdidumm

@ivanhofer @dummdidumm Is this somehow related? https://github.com/sveltejs/kit/issues/7914#issuecomment-1347002959

lukaszpolowczyk avatar Dec 14 '22 14:12 lukaszpolowczyk

I was confused by the changes here, turns out the server is returning the correct response, Simon's right on handle_fatal_error being able to deal with this already, the problem is on the client side.

Here load_data creates an error object, which is caught and passed in here but there is no status information in that catch clause so it just shows a generic 500.

Also related and probably can be solved at the same time, because of the same "just thrown a native Error" mechanic, the HttpError from the server is never actually instantiated into an HttpError in the browser.

gtm-nayan avatar Feb 01 '23 10:02 gtm-nayan

@gtm-nayan thanks for your investigation. Haven't had the time to follow up on this issue. But it seems my assumption was wrong and this PR does not make sense at all. I will close it.

ivanhofer avatar Feb 01 '23 13:02 ivanhofer