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

Unhandled rejection in can/map/map #482

Open
chasenlehara opened this issue May 29, 2019 · 0 comments
Open

Unhandled rejection in can/map/map #482

chasenlehara opened this issue May 29, 2019 · 0 comments
Assignees
Labels

Comments

@chasenlehara
Copy link
Member

chasenlehara commented May 29, 2019

The following line of code always creates a new Promise:

promise.then(success,error);

When the user calls .save() on an instance and doesn’t pass in an error handler, the Promise is still created, and if it errors then an unhandledrejection event is dispatched.

I believe that line should be changed to something like:

if (success !== undefined || error !== undefined) {
  promise.then(success, error);
}

This will make it so the user can still pass in success or error. If they only pass in success, then the unhandled rejection event will still be created. If they don’t pass in either, then it will be up to them to catch the error from the Promise that’s returned.


For context, I found this while upgrade can-connect-feathers to use QUnit 2. That package has tests that check errors in different scenarios. QUnit 2 will fail a test that causes unhandled rejections, so the line above was causing some tests to fail even when they were working correctly.

Here’s an example of a test that fails in QUnit 2:

		session.save()
		.then(function (res) {
			console.log('res', res);
		})
		.catch(function (err) {
			assert.equal(err.name, 'NotAuthenticated', "got back error message: "+err.name);
			done();
		});

This test should pass because it catches the error, but it fails because QUnit 2 listens for any unhandled rejections. There’s an unhandled rejection because the promise.then(success, error); line creates a new Promise that’s rejected, but there’s no error handler passed to .save().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants