Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make sure promises from fetch handle errors #11228

Merged
merged 1 commit into from Dec 9, 2023
Merged

Conversation

dummdidumm
Copy link
Member

Ensures that people using fetch directly in their load functions don't run into uncaught promise errors with streaming. Also adds some docs for this case.
related to #9785

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

  • 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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • 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. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Dec 8, 2023

🦋 Changeset detected

Latest commit: b2960d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

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

Ensures that people using `fetch` directly in their load functions don't run into uncaught promise errors with streaming.
Also adds some docs for this case.
related to #9785
@Conduitry
Copy link
Member

I think this sort of change to our server-side fetch function makes sense - regardless of how else we decide we want to deal with unhandled promise rejections happening in user code. We should at the very least be attempting not to cause these sorts of problems within framework code.

As I mentioned in Discord, I think what makes sense is adding an uncaughtExceptionMonitor event handler in dev only that checks for unhandledRejection errors, prints out a link to some documentation, and then lets the process crash normally unless the user has attached their own unhandledRejection handler. I don't think we can do better than that without stepping on people's toes.

@benmccann
Copy link
Member

We could also maybe add a commented out unhandledRejection handler to hooks.js with a comment saying to uncomment it if you're using adapter-node? Or possibly we could add one automatically in the adapter-node output, but we'd have to see what happens if two are provided (e.g. maybe Sentry provides one?)

@Rich-Harris Rich-Harris merged commit 15422d2 into master Dec 9, 2023
14 checks passed
@Rich-Harris Rich-Harris deleted the fetch-catch branch December 9, 2023 02:00
@github-actions github-actions bot mentioned this pull request Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants