-
-
Notifications
You must be signed in to change notification settings - Fork 26.6k
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
What should the behavior of an exception inside a promise be? #5787
Comments
They all fail on chrome and firefox for me with an uncaught exception. The issue is in using It's true that an You can either remove the |
I'm not sure I follow what you mean by Many of the examples don't resolve immediately (as that's the whole point). Imagine my toLowerCase were actually toLowerCaseAsync() above and required an await. This example for instance
I can't really see how to do this without creating a promise with an async executor. |
It doesn’t have to call resolve or reject now, it just has to call one of them eventually. The executor doesn’t expect a promise to be returned; the type is You generally only use async function readAsDataUrl(response: Response): Promise<string> {
const blob = await response.blob();
const result = await readDataUrlFromBlob(blob);
return result;
}
function readDataUrlFromBlob(blob: Blob): Promise<string> {
return new Promise<string>((resolve, reject) => {
const fr = new FileReader();
fr.onload = () => {
resolve(fr.result as string);
};
fr.onerror = () => {
reject(fr.error);
}
fr.readAsDataURL(blob);
});
} |
Is this a bug report?
No/Maybe
I have a section of code (in typescript using "react-scripts": "2.1.1") that generates a promise that is used later. Inside that promise, I occasionally will get a bad object, and expect the promise to be rejected as a result of an object being undefined. Here's a pathological example, where I force the variable a to be undefined to illustrate the problem, which gives
Unhandled Rejection (TypeError): Cannot read property 'toLowerCase' of undefined
On chrome this generates an exception at runtime when running the debug build, which prevents any further use of the app, but does not on edge.
If instead, I rewrite it like this, it also fails on chrome.
This too fails, making it look like anything thrown that derives from error causes the message:
however if I rewrite it like this, it does not fail on chrome.
The text was updated successfully, but these errors were encountered: