Comments (5)
I'm considering adding the following "info" level logging to Deferred and Promise operations:
- for when then() is called:
- immediately at the start of that call:
Registering callbacks with Deferred.
- just before then() returns the new Promise:
Returning a Promise of the transformed result.
- immediately at the start of that call:
- for the Promise returned by a call to then()
- when that Promise returns a Promise:
Promise will be completed based on the Promise returned by its callback.
- when that Promise returns a value:
Promise resolved with the value returned by its callback: <value>
- when that Promise throws an Error:
Promise rejected with the Error returned by its callback: <error.stack>
- when that Promise returns a Promise:
- for any Deferred
- when update() is called:
Deferred updated with progress: <progress>
- when resolve() is called:
Deferred resolved with value: <value>
- when reject() is called:
Deferred resolved with error: <error>
- when cancel() is called:
Deferred cancelled with reason: <reason>
- when update() is called:
Does this seem like an appropriate level of logging coverage?
Additionally, in order to aid developers in debugging logic that relies on Promises and Deferreds, I'm considering adding an optional id
property to Deferreds. When specified, the logging messages above would be modified to include that identifier.
Thoughts?
from deftjs.
The coverage seems fine to me. The identifier should definitely be useful. Maybe it would help to use a different terminology for the Promise created and controlled directly by the user code, and the Promises created by calls to then(). Maybe "Delegate Promise" ?
The "Promise rejected with the Error raised by its callback" message would address issue #59. IMO however, when an error is raised in a callback and there is no registered failure callback to notify, that should be considered an uncatched exception, and so it would be appropriate to log it with an "error" level. That's something you want to see in red in the console, especially if it happens in a production environment where ext-dev has not been included.
Was it really a good idea for the spec that the only way to pass an error to the following promises is by throwing it? Returning (instead of throwing) an instance of an Error object would spare that dangerous catch-all block. Mixing managed errors and unexpected exceptions seems a bit messy to me. I am curious to know what you think about that?
from deftjs.
In practice, this approach has proven much too verbose to be useful.
- Internal Promises used within the Promise helper methods emit detailed logging that is irrelevant to user code.
- Often the Promise you care about is one that was created as a result of then() chaining, and that Promise can't easily be tagged with an identifier.
- Valuable logging gets lost in the noise.
- In a production environment where ext-dev has not been included, real errors are swallowed and go unreported.
Deft JS 0.9 will implement a new helper method available on all Promises called log()
. It can be used anywhere in a Promise chain and will log the resolution or rejection of the preceding Promise, passing the result through to allow for further chaining and transformation. log()
will support an optional name parameter that is incorporated into the resulting logging message.
Example:
getUser(currentUserId)
.log("Promise of the current User")
.then( function (user) {
return Promise.map(user.friendIds, getUser)
})
.log("Promise of a User's friends");
.done();
In this contrived example, we get the details for a user and use Promise.map()
to get the details for all of the user's friends.
The log output for fulfilled Promises would look like this:
[I] Promise of the current User resolved with value: <value>
[I] Promise of a User's friends resolved with value: <value>
The log output for rejected Promises would look like this:
[I] Promise of the current User rejected with error: <error>
[I] Promise of a User's friends rejected with error: <error>
Also note the use of done()
, which will also be part of Deft JS 0.9. By placing the done() at the end of this chain, any unhanded rejections earlier in the Promise chain will throw an Error. See #83 for more details.
from deftjs.
This feature and its associated unit tests have been implemented in the promises_aplus
branch and will be part of the Deft JS 0.9 release.
from deftjs.
Deft.Promise::log() is now available as part of the new Promises/A+ compliant rewrite of Deft JS's Promises.
See also: #82
from deftjs.
Related Issues (20)
- DeftJS v0.9 - Promises not working in Internet Explorer 10 HOT 6
- Distribute packages separately. HOT 4
- Update Karma configurations from v0.8 -> v0.10 syntax HOT 1
- Add continuous deployment HOT 10
- Add Ext JS 4.2.2 to the Deft JS Test Suite HOT 2
- Add Sencha Touch 2.3.0 to the Deft JS Test Suite HOT 1
- Update the Test Suite dependencies (Mocha, Chai, Sinon, Promise/A+, etc.)
- Update to Promises/A+ Specification v1.1 and Test Suite v2.0
- Failing to require: the ViewController for a controller: annotation should trigger a warning.
- Sencha Cmd v4.0.0.203 hanging when "requires" : "[email protected]?" added HOT 14
- Migrate back to mixins for Sencha Cmd and Architect compatibility
- Suppress INFO-level log messages when not using the debug build of Sencha Touch HOT 1
- Superclass merging of ViewController 'control:' configurations
- ViewController companions HOT 4
- Touch 2.3.0 coverage report might overwrite 2.2.1 report
- deft.js and deft-debug.js are not in the repo HOT 1
- Sencha cmd 5.0.3 and touch 2.4.1 - build failed HOT 16
- Sencha 2 Routing with Deft JS.. HOT 1
- DeftJS 8.0-9.1Promise/Deferred Memory Usage HOT 5
- Promises catching errors happening in the success method HOT 1
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 deftjs.