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

add tapError #1220

Merged
merged 7 commits into from
Mar 3, 2017
Merged

add tapError #1220

merged 7 commits into from
Mar 3, 2017

Conversation

benjamingr
Copy link
Collaborator

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.

@joepie91
Copy link

joepie91 commented Aug 31, 2016

Hmm. Is this meant to be equivalent to .error or to .catch?

@petkaantonov
Copy link
Owner

There should also be cancellation tests, see how .tap is tested in test/cancel.js

@@ -0,0 +1,128 @@
---
layout: api
id: tap
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tapError

@benjamingr
Copy link
Collaborator Author

Hmm. Is this meant to be equivalent to .error or to .catch?

To .catch (both the catch all variant and the filtered one.

@joepie91
Copy link

To .catch (both the catch all variant and the filtered one.

Hmm, shouldn't we name it .tapCatch then? Otherwise, I can see this causing some confusion for users, thinking that it's equivalent to .error.

@petkaantonov
Copy link
Owner

Yeah tapCatch is probably a better name for this

@benjamingr
Copy link
Collaborator Author

  • Renaming to catch.
  • Fixing the doc issues.
  • I don't see tap in the cancellation tests.
  • Using the same NEXT_FILTER.

Predicates still don't work, PTAL.

src/finally.js Outdated
return this._passThrough(handler,
TAP_TYPE,
undefined,
catchFilter(predicate, handler, this));
Copy link
Owner

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)

Copy link
Collaborator Author

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 -_-

Copy link
Owner

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);

Copy link
Collaborator Author

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.

@petkaantonov
Copy link
Owner

I don't see tap in the cancellation tests.

never mind then, remembered wrong

@benjamingr
Copy link
Collaborator Author

@petkaantonov do we really need to support the multi parameter syntax? I'm fine with just supporting .tapCatch(e => {}) and .tapCatch(type|predicate, e => {})


describe("tap", function () {
specify("passes through rejection reason", function() {
return Promise.reject("test").tapError(function() {
Copy link
Owner

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

@petkaantonov
Copy link
Owner

No but the predicate should still be type checked at this point, otherwise confusing error will happen at some later point

@benjamingr
Copy link
Collaborator Author

Addressed the feedback but predicate tests still don't pass.

@petkaantonov
Copy link
Owner

The finallyHandler needs to be modified to:

if (ret === NEXT_FILTER) {
    return ret;
} else if (ret !== undefined) {
    ...

@benjamingr
Copy link
Collaborator Author

Still no dice

@petkaantonov
Copy link
Owner

Run it individually to see the reason for failure node tools/test --run=tapCatch, for instance you have typed RefernceError instead of ReferenceError in one of the predicate tests

@benjamingr
Copy link
Collaborator Author

I did, that's not why it's failing. I see an assertionError, I don't really understand catchFilter very well - any chance you could take a look tonight before you release and see what I did wrong?

@benjamingr
Copy link
Collaborator Author

Ping @petkaantonov

@@ -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)

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),
Copy link
Contributor

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.

called = true;
}).then(assert.fail, function(err) {
assert(called === false);
assert(err instanceof ReferenceError);
Copy link
Contributor

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.

@Retsam
Copy link
Contributor

Retsam commented Feb 27, 2017

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. (Still need to add type checking for predicates)

* 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
@petkaantonov petkaantonov merged commit 053d02e into master Mar 3, 2017
@petkaantonov petkaantonov deleted the add-tapErrr branch March 3, 2017 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants