-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
add tapError #1220
add tapError #1220
Conversation
Hmm. Is this meant to be equivalent to |
There should also be cancellation tests, see how .tap is tested in test/cancel.js |
docs/docs/api/tapError.md
Outdated
@@ -0,0 +1,128 @@ | |||
--- | |||
layout: api | |||
id: tap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tapError
To |
Hmm, shouldn't we name it |
Yeah tapCatch is probably a better name for this |
Predicates still don't work, PTAL. |
src/finally.js
Outdated
return this._passThrough(handler, | ||
TAP_TYPE, | ||
undefined, | ||
catchFilter(predicate, handler, this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be catchFilter(predicate, finallyHandler, this)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, I spent like 20 minutes thinking what I'm not understanding in catchFilter and it ended up being a mistype -_-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also on top of modifying the finallyHandler, it should probably be:
return this._passThrough(catchFilter(predicate, handler, this),
TAP_TYPE,
undefined,
finallyHandler);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't fix it either.
never mind then, remembered wrong |
@petkaantonov do we really need to support the multi parameter syntax? I'm fine with just supporting |
test/mocha/tapCatch.js
Outdated
|
||
describe("tap", function () { | ||
specify("passes through rejection reason", function() { | ||
return Promise.reject("test").tapError(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use new Error and assign it to variable, because this will cause a warning
No but the predicate should still be type checked at this point, otherwise confusing error will happen at some later point |
Addressed the feedback but predicate tests still don't pass. |
The finallyHandler needs to be modified to: if (ret === NEXT_FILTER) {
return ret;
} else if (ret !== undefined) {
... |
Still no dice |
Run it individually to see the reason for failure |
I did, that's not why it's failing. I see an assertionError, I don't really understand |
Ping @petkaantonov |
docs/docs/api-reference.md
Outdated
@@ -53,7 +53,7 @@ redirect_from: "/docs/api/index.html" | |||
- [Promise.using](api/promise.using.html) | |||
- [.disposer](api/disposer.html) | |||
- [Promisification](api/promisification.html) | |||
- [Promise.promisify](api/promise.promisify.html) | |||
- [Promise.promisify](api/promsie.promisify.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo?
src/finally.js
Outdated
} else { | ||
var predicate = arguments[0]; | ||
var handler = arguments[1]; | ||
return this._passThrough(catchFilter(predicate, handler, this), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like catchFilter
is expecting an array of predicates, not a single predicate; this is why the "Works with predicates" test is failing.
test/mocha/tapCatch.js
Outdated
called = true; | ||
}).then(assert.fail, function(err) { | ||
assert(called === false); | ||
assert(err instanceof ReferenceError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this should be err instanceof TypeError
.
I'd love to see this feature go in; I've opened #1351 as an extension of this PR with my fixes for most of the above issues. ( |
* Fix typo: ReferneceError -> ReferenceError * Fix typo: promsie -> promise * s/tapError/tapCatch/g * Pass an array of predicates to catchFilter in tapCatch * Fix tapCatch tests * Add support for multiple predicates and predicate type checking
Adds
Promise.prototype.tapError
to bluebird.The tests for the predicate version aren't passing yet (not sure why) and the doc is still missing, will hopefully follow up with those before I run out of momentum.