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 handleRejections support #1462

Merged
merged 5 commits into from
Dec 26, 2018
Merged

Add handleRejections support #1462

merged 5 commits into from
Dec 26, 2018

Conversation

drazisil
Copy link
Contributor

@drazisil drazisil commented Sep 9, 2018

Adds #921

However, needs some work because, although this seems like it should work, I don't think the tests are right since no log is created in fixtures.

It almost feels like it's silently not working, but I can't figure out how to get past mocha's "make sure your promise resolves" in order to test that it rejects. (and handled by winston)

Hope this is a good starting point for someone. Leaving the WIP tag to indicate it shouldn't be merged without double-checking the testing.

@drazisil drazisil changed the title [WIP ]Add handleRejections support [WIP] Add handleRejections support Sep 9, 2018
@DABH DABH mentioned this pull request Sep 21, 2018
@DABH
Copy link
Contributor

DABH commented Sep 21, 2018

Thanks for this PR! Looks very nice! 😎 Folks have wanted this feature for a while.

Re: tests, do you have e.g. a plain node.js file you or I can run to see if this works or not (i.e., outside of mocha or any other test frameworks)? I can take a look at the mocha stuff but it would be helpful to have some starting point for testing. Thanks again for your work on this!

@drazisil
Copy link
Contributor Author

drazisil commented Sep 21, 2018

@DABH The below code will throw an unhandled rejection:

var promise1 = new Promise(function(resolve, reject) {
  setTimeout(function() {
    reject('foo')
  }, 100)
})
(node:19646) UnhandledPromiseRejectionWarning: foo
(node:19646) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:19646) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Under Node 8.11. I tried figuring out a way to test it but didn't have much success.

@drazisil
Copy link
Contributor Author

drazisil commented Nov 17, 2018

Updated package-lock.json so there are no conflicts. Since the changes are approved, will this be merged soon? Not sure if anyone has looked into the testing. cc: @DABH

@avik-so
Copy link

avik-so commented Nov 27, 2018

Hi, is this fix safe? Our team is relying on it but was waiting for it to be officially merged into the project.

@awill1988
Copy link

Please merge!

Copy link

@awill1988 awill1988 left a comment

Choose a reason for hiding this comment

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

Line 87 in lib/winston/rejection-handler.js has a typo, unhandledJejection

@drazisil
Copy link
Contributor Author

Corrected, @awill1988

@indexzero
Copy link
Member

Howdy folks – life happened for a little while over here. @DABH and I have monthly syncs to review & triage large features like this, but I missed the last two 😳

As such we'll be doing some overdue (my fault) maintenance in the next week or so. Keep an eye out for a minor release.

In principle winston needs to handle uncaughtRejection – appreciate someone from the community digging in and taking a stab implementing it.

@kingnebby
Copy link

@indexzero - may I just say thank you for being awesome. No need to apologize for that.

@DABH
Copy link
Contributor

DABH commented Nov 29, 2018

Since tests look like they're passing now, I think that this should be able to drop in the next release. I looked through the code again and it still looks good. The one thing I'm concerned about is exit behavior -- with ExceptionHandler, there are several open issues right now about e.g. exceptions not being logged before the program exits (I have a PR to fix that though). But I wonder if there's a similar issue with rejections since code is mostly same as ExceptionHandler. In any case we could probably look into that after merging this, especially if people are already using this feature branch and finding it useful/working.

@ejmartin504
Copy link
Contributor

FWIW I would love to see this merged / released as well, and I'd be happy to help out with any outstanding issues that give you pause @DABH :-)

@indexzero indexzero added Feature Request Request for new functionality to support use cases not already covered Important labels Dec 7, 2018
@indexzero indexzero changed the title [WIP] Add handleRejections support Add handleRejections support Dec 26, 2018
@indexzero
Copy link
Member

Reviewed this with @DABH today and we are 👍 – David is going to apply his fix from #1355 to this post-merge and then it will go out in 3.2.0. See the remaining issues in the release.

@indexzero indexzero merged commit 766dc0c into winstonjs:master Dec 26, 2018
Mizumaki pushed a commit to Mizumaki/winston that referenced this pull request Jun 11, 2020
* Add handleRejections suppot

* Correct typo
@glensc
Copy link

glensc commented Sep 15, 2020

Adds missing typescript typings: #1842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Request for new functionality to support use cases not already covered Important
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants