Comments (8)
However, Javascript is a dynamic language, for all the implementations unhandled rejection
is just a guess, you never know if an async error is handled at some point in the future . For example, no implementation can handle the code below correctly:
var p = Promise.reject()
setTimeout(() => {
p.catch(() => {})
}, 1e9)
Actually the vm needs to understand the meaning of your code to handle it correctly, which is apparently impossible at current AI tech.
So, the problem changes to make the guess warning less annoying. To suppress it as much as possible.
Your p1
andy p2
is just containers, they contain the same error value. Why we should waste cpu to log it twice?
from yaku.
Another thing the spec doesn't mention is what is an unhandled rejection
philosophically?
This code:
p0 = Yaku.resolve().then(function () {
abc()
})
p1 = p0.then(function () {})
p2 = p0.then(function () {})
p3 = p0.catch(function () {})
Apparently has a handler for the original rejection.
But on the other side, you could also say it doesn't have a handler for the inherent rejections.
It really depends on your definition of unhandled rejection
.
from yaku.
However, Javascript is a dynamic language, for all the implementations unhandled rejection is just a guess, you never know if an async error is handled at some point in the future.
Right, which is why both unhandledrejection
and rejectionhandled
events are emitted. It's up to the user to listen to both and reconcile the two to determine the unhandled promise rejections. For example: https://googlechrome.github.io/samples/promise-rejection-events/index.html
Your p1 andy p2 is just containers, they contain the same error value. Why we should waste cpu to log it twice?
Because it's the spec. If I'm writing an error reporting framework, I want to build it on top of how the spec works (i.e. it works the the same with native promises and Yaku).
from yaku.
I prefer the original rejection
as I mentioned, it's more intuitive.
from yaku.
Fair enough, feel free to close this issue if you disagree.
However, my personal opinion is that it should conform to the spec rather than use some special snowflake logic on how these events operate.
from yaku.
What spec do you mean? unhandled rejection
is not a part of ES spec, Chrome is not a spec. For me it's a runtime decision.
from yaku.
It's not codified in ECMAScript, which only suggests a typical implementation for HostPromiseRejectionTracker
:
A typical implementation of HostPromiseRejectionTracker might try to notify developers of unhandled rejections, while also being careful to notify them if such previous notifications are later invalidated by new handlers being attached.
However, I think browser unhandledrejection
and rejectionhandled
events are part of a codified browser spec (not just Chrome), which does dictate behavior. It is not up to the runtime (for browsers):
https://html.spec.whatwg.org/multipage/webappapis.html#unhandled-promise-rejections
https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation
from yaku.
That why I said Chrome doesn't handle it improperly here: https://github.com/ysmood/yaku/blob/master/docs/debugHelperComparison.md#better-unhandled-error
If I think they are all right, why would I take time to optimize the behavior? If I follow them, the codebase could be smaller.
I hope my thoughts could help to evolve the spec
from yaku.
Related Issues (20)
- Only the core works well with old browsers HOT 1
- Something strange (Slow resolve on pageload) HOT 23
- Yaku doesn't work if div with id="process" exists HOT 2
- Can't register global unhandled rejection HOT 1
- Does not work on UC Browser HOT 9
- Yaku.all is overridden by yaku/utils/all on yaku.brower.full.min.js version HOT 3
- difference between return Promise.reject(x) and throw x HOT 7
- Finally swallows rejections HOT 4
- Bind to Angular 1.x digest? HOT 6
- Bad references in package.json HOT 1
- 0.18.3 is broken if window.Promise is set to Yaku HOT 3
- Implement Promise.try() ? HOT 1
- Incorrect promise when calling `resolve` twice HOT 1
- global.Promise should be non-enumerable and should have correct name property HOT 5
- "hash" util/helper request HOT 3
- Mock Mode HOT 7
- Support for Promise.allSetteled HOT 2
- Bug: Stealing a resolver and using it to trigger reentrancy HOT 3
- Promise.all and Promise.allSettled doesn't work if the promise array has been created in a different frame. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaku.