-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
process: add 'warning' event #5440
Conversation
In general, this looks good... it means a bit more work for someone adding a new warning but that's perfectly fine. Those changes look fine. I am a bit concerned that someone would need to make sure to set the The |
I share similar concerns with @jasnell, perhaps an |
// is shown. This takes backwards compatibility with --trace-deprecation | ||
// into consideration also. | ||
if (!process.noProcessWarnings) { | ||
var message = warning.message; |
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.
Shouldn't it be const message
?
I think it would be useful to have either |
The entire Express.js code base deals with deprecations in a similar way, hooking into Express.js further provides mechanisms to suppress deprecations on a module-by-module basis, rather that only all or nothing (though you can do all-or-nothing, either by using the Anyway, I just happened to stumble on this issue and just wanted to provide my 2c on what Express.js has been doing for almost 2 years now. My main concern with this pull request is that it adds a new |
`leak detected. ${existing.length} ${type} listeners added. ` + | ||
`Use emitter.setMaxListeners() to increase limit.`); | ||
warning.name = 'BadPracticeWarning'; | ||
process.emit('warning', warning); |
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.
The warnings really ought to be emitted on the next tick
@cjihrig ... it's worth noting that the |
Comparing this with my original #4782 ... I think I still favor mine albeit with a number of the changes suggested here. I will be pushing an update shortly with those changes. The approach I take ensure that there will be more consistency in the way the warnings are structured and emitted and hides some of that complexity from the code where the warning is actually being emitted. |
I have pushed some updates to #4782 that incorporate a number of these changes. PTAL |
@jasnell, any thoughts on the concern I brought up? |
a260e1e
to
69ad541
Compare
Updated with feedback. This is very much the same as the PR from @jasnell, only without the custom warning wrapper. I also changed the signature of |
@geek ... btw, thanks for this PR ;-) .. whichever one lands ultimately will be good I think @dougwilson ... I'd rather not have separate |
@dougwilson ... just looking at depd again... and I think you've swayed me. This is an opportunity to get some good alignment between core and express. It would be fairly trivial to implement this and the inclusion of the Could depd be updated to make use of the new |
@dougwilson ... one thing on this tho... there would be a default handler registered for the |
Hi @jasnell, I would really want to tie that module into this mechanism, which is why I looked at this PR when I saw it's title when browsing Node.js issues :) Having a common mechanism is awesome in the long run, and really I would say probably an aspect of
That is actually OK, because it means that all existing users who are just getting the default message printing will automatically get formatting from Node.js core. There isn't a default listener for |
And in case the description of how var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('hi!');
});
app.del('/', function (req, res) {
res.send('bye!');
});
app.listen(4000); When you invoke that file with
It would be nice if this default-ness would be preserved in some way, but perhaps that is a different issue with the implemented
Which a use can kind of figure out where they went wrong, assuming that they have a very tiny codebase, and are not using a ton of I have found with the existing warnings that Node.js provides (and this pull request would continue to provide) is extremely confusing to users, and they end up simply trying to use I hope this helps think about the feature and how it can best help the Node.js users. |
Yep, once we're a bit more settled on the general mechanism, I'd like to work on the default formatting. I'm looking at possible adding the |
Yes, sorry. I originally made my comment in the other PR, but then it had looked like (at least as an outsider), that the work moved over here, so I had moved my concern here as well, I will continue discussion over there :) |
James' version landed in c6656db, thanks for the input! |
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)? need to fix eslint rule for allowing template strings
test (or a benchmark) included?
existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Affected core subsystem(s)
process
Description of change
This is a modified version of the pull request from @jasnell at #4782
Instead of creating custom warning types, this PR uses the Error object and adds a name property that represents the type of warning thats emitted. The
emitWarning
does't exist in this PR, it didn't seem necessary. Also, I didn't add theSecurityWarning
type, as its not used./cc @rvagg see what you think