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

Abort unhandledRejection when Promise does not handle exceptions. #13

Merged
merged 1 commit into from
Apr 18, 2016

Conversation

yosuke-furukawa
Copy link
Owner

Current Node process does not abort on unhandledRejection.
So if developers write the following sample test code,

const assert = require('assert');

function testRejectPromise() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject(new Error('test'));
    }, 100);
  });
}

testRejectPromise().then(() => {
  assert('test');
});

eater cannot catch the error.

workaround is here.

const assert = require('power-assert');

function testRejectPromise() {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject(new Error('test'));
    }, 100);
  });
}

testRejectPromise().then(() => {
  assert('test');
});

process.on('unhandledRejection', (e) => {
   console.error(e);
});

After merging this PR, eater can handle unhandledRejection when promise reject an exception.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 939f83c on add_promise_unhandled_rejection into 88643e4 on master.

@yosuke-furukawa
Copy link
Owner Author

if this issue is solved, I can revert this commit :)
nodejs/promises#26

@yosuke-furukawa yosuke-furukawa merged commit 7facaa0 into master Apr 18, 2016
@yosuke-furukawa yosuke-furukawa deleted the add_promise_unhandled_rejection branch April 18, 2016 18:35
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.

2 participants