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

Handle unhandled promise rejections #4366

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Jul 14, 2024

  • users need this feedback in case something goes wrong

- users need this feedback in case something goes wrong
@github-actions github-actions bot added the app label Jul 14, 2024
@mtsgrd mtsgrd requested a review from ndom91 July 14, 2024 10:42
@mtsgrd mtsgrd force-pushed the Handle-unhandled-promise-rejections branch from 187213e to cbe4f5f Compare July 14, 2024 10:48
@mtsgrd mtsgrd merged commit f197e8b into master Jul 14, 2024
11 of 12 checks passed
@mtsgrd mtsgrd deleted the Handle-unhandled-promise-rejections branch July 14, 2024 11:55
@ndom91
Copy link
Contributor

ndom91 commented Jul 14, 2024

Maybe I'm missing something, but it should still be shown to the user before.

The error would be returned here from handleError handle and from there available in the $page.error store in the layout.svelte/page.svelte file and shown to the user via showError there

EDIT: Ah but does the handler only handle thrown errors and not unhandled rejected promises?

@mtsgrd
Copy link
Contributor Author

mtsgrd commented Jul 14, 2024

Yeah, promises are special, SvelteKit doesn't intercept them. ✌️

@Caleb-T-Owens
Copy link
Contributor

Promises are equivalent to a lazily evaluated Result<> type.

An async function that throws an exception, IE:

async function foo() {
  if (false) {
    return "sadf"
  } else {
    throw new Error("asdf")
  }
}

is more or less the same as saying:

function foo() {
  return new Promise((resolve, reject) => {
    if (false) {
      return resolve("sadf")
    } else {
      return reject(new Error("asdf"))
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants