-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 emitExperimentalWarning() #9042
Conversation
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.
Good start but can be better. Left a few comments.
lib/internal/process/warning.js
Outdated
class ExperimentalWarning extends Error { | ||
constructor(feature) { | ||
super(`${feature} is an experimental feature.`); | ||
this.name = '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.
Would recommend a name like ExperimentalWarning
lib/internal/process/warning.js
Outdated
@@ -4,6 +4,17 @@ const prefix = `(${process.release.name}:${process.pid}) `; | |||
|
|||
exports.setup = setupProcessWarnings; | |||
|
|||
class ExperimentalWarning extends Error { | |||
constructor(feature) { | |||
super(`${feature} is an experimental feature.`); |
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.
Perhaps a notice such as:
super(`${feature} is an experimental feature. Implementation details may change.`);
lib/internal/process/warning.js
Outdated
@@ -46,4 +57,8 @@ function setupProcessWarnings() { | |||
} | |||
process.nextTick(() => process.emit('warning', warning)); | |||
}; | |||
|
|||
process.emitExperimentalWarning = function(name) { | |||
process.emitWarning(new ExperimentalWarning(name)); |
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.
There's no reason to create a separate class for this, something like the following would work easily...
const msg = `${feature} is an experimental feature. ` +
'Implementation details may change.';
process.emitWarning(msg, 'ExperimentalWarning');
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.
ack, fixed
4c7d7d1
to
2806e9e
Compare
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.
LGTM, but we're going to be stuck supporting process._useInspector
for a long time.
@cjihrig yea, i'll fix that. I don't want to pollute process anymore than we have to |
const assert = require('assert'); | ||
const exec = require('child_process').exec; | ||
|
||
if (process.argv[2] === 'child') { |
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.
Why use a child_process
here?
The following should work fine...
process.on('warning', common.mustCall((warning) => {
assert.strictEqual(warning.name, 'ExperimentalWarning');
assert.strictEqual(warning.message, message);
}));
process.emitExperimentalWarning('new_feature');
There are other existing tests that validate that warnings are printed to stderr appropriately.
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.
ack
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.
Even better:
common.expectWarning('ExperimentalWarning', message);
process.emitExperimentalWarning('new_feature');
process.emitExperimentalWarning('new_feature');
(call it twice to make sure it is not emitted more than once)
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.
hm, even though warnings can be emitted more than once? I guess it could make sense to only emit the experimental warning for each feature once?
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.
Should only be once I think.
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 test exemplifies my first comment imo, the fact that a child process is necessary.
lib/internal/bootstrap_node.js
Outdated
// TODO(evanlucas) Remove this when v8_inspector is no longer experimental. | ||
if (process._useInspector) { | ||
process.emitExperimentalWarning('v8_inspector'); | ||
} |
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.
This should be after setupRawDebug()
at minimum.
However, I think this probably needs to happen at the end of the first tick?
i.e. do we want user handlers to catch this?
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.
ah yea, good point
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.
So, process.emitWarning currently emits the warning using process.nextTick()
. Will that be sufficient or does it need an additional setImmediate()
?
lib/internal/process/warning.js
Outdated
|
||
process.emitExperimentalWarning = function(feature) { | ||
const msg = `${feature} is an experimental feature. ` + | ||
'Implementation details may change.'; |
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.
I think the wording should be improved... the exposed feature could change at any time.
This adds process.emitExperimentalWarning() which can used to communicate to our users that a feature they are using is experimental and can be changed/removed at any time. Ref: nodejs#9036
2806e9e
to
a7365f9
Compare
c133999
to
83c7a88
Compare
New CI: https://ci.nodejs.org/job/node-test-pull-request/4580/ |
@evanlucas ... CI looks good. Want to get this landed? |
I don't think this ever addressed my comment? |
lib/internal/bootstrap_node.js
Outdated
@@ -50,6 +50,11 @@ | |||
|
|||
_process.setupRawDebug(); | |||
|
|||
// TODO(evanlucas) Remove this when v8_inspector is no longer experimental. | |||
if (process.execArgv.indexOf('--inspect') !== -1) { | |||
process.emitExperimentalWarning('v8_inspector'); |
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.
gets emitted before a listener can be attached
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.
even though the warning is emitted in a process.nextTick()
(https://github.com/nodejs/node/blob/master/lib/internal/process/warning.js#L47)?
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.
Yes, in both the REPL and case like node foo.js
, the warning is emitted before user code is invoked. Setting a pre-load module using -r
allows the warning event to be listened for.
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.
ahhh ok, sorry about that. Will get that fixed this weekend. Thanks!
'change at any time.'; | ||
common.expectWarning('ExperimentalWarning', warning); | ||
process.emitExperimentalWarning('new_feature'); | ||
process.emitExperimentalWarning('new_feature'); |
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.
why twice here?
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.
to make sure it is only emitted once
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 emit timing on that one needs to be addressed
This is a good candidate for backporting to v4 and v6, what think you @nodejs/LTS? |
With exception to the DeprecationWarning pieces, yes I agree. process On Saturday, October 29, 2016, Rod Vagg notifications@github.com wrote:
|
Oh ya, I forgot for a moment that the whole api was missing in v4. Easier case to limit backporting this bit to v6 at this stage probably. |
This is currently an experimental feature, so we should make sure users are aware that it can be changed at any time. Ref: nodejs#9036
a7365f9
to
0322d54
Compare
@evanlucas ... still want to pursue this? |
Going to close for now. I may have time in the near future to do this or not, but someone else can pick up if they want :] |
Also, perhaps we could use a Symbol to make it less accessible since it seems like this is for internal use only? |
I'll throw this on my todo list to look into |
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
process, internal
Description of change
This adds process.emitExperimentalWarning() which can used to
communicate to our users that a feature they are using is experimental
and can be changed/removed at any time. There is also a commit included
to use this api whenever the inspector is used.
Ref: #9036