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

process: add emitExperimentalWarning() #9042

Closed
wants to merge 2 commits into from

Conversation

evanlucas
Copy link
Contributor

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected 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

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 11, 2016
@evanlucas evanlucas added the process Issues and PRs related to the process subsystem. label Oct 11, 2016
Copy link
Member

@jasnell jasnell left a 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.

class ExperimentalWarning extends Error {
constructor(feature) {
super(`${feature} is an experimental feature.`);
this.name = 'Warning';
Copy link
Member

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

@@ -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.`);
Copy link
Member

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.`);

@@ -46,4 +57,8 @@ function setupProcessWarnings() {
}
process.nextTick(() => process.emit('warning', warning));
};

process.emitExperimentalWarning = function(name) {
process.emitWarning(new ExperimentalWarning(name));
Copy link
Member

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');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack, fixed

Copy link
Contributor

@cjihrig cjihrig left a 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.

@evanlucas
Copy link
Contributor Author

@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') {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

@Fishrock123 Fishrock123 left a 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.

// TODO(evanlucas) Remove this when v8_inspector is no longer experimental.
if (process._useInspector) {
process.emitExperimentalWarning('v8_inspector');
}
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yea, good point

Copy link
Contributor Author

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()?


process.emitExperimentalWarning = function(feature) {
const msg = `${feature} is an experimental feature. ` +
'Implementation details may change.';
Copy link
Contributor

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
@jasnell
Copy link
Member

jasnell commented Oct 19, 2016

New CI: https://ci.nodejs.org/job/node-test-pull-request/4580/
LGTM if CI is green.

@jasnell
Copy link
Member

jasnell commented Oct 26, 2016

@jasnell
Copy link
Member

jasnell commented Oct 28, 2016

@evanlucas ... CI looks good. Want to get this landed?

@Fishrock123
Copy link
Contributor

I don't think this ever addressed my comment?

@@ -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');
Copy link
Contributor

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

Copy link
Contributor Author

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)?

Copy link
Member

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.

Copy link
Contributor Author

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');
Copy link
Contributor

Choose a reason for hiding this comment

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

why twice here?

Copy link
Contributor Author

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

Copy link
Contributor

@Fishrock123 Fishrock123 left a 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

@rvagg
Copy link
Member

rvagg commented Oct 29, 2016

This is a good candidate for backporting to v4 and v6, what think you @nodejs/LTS?

@jasnell
Copy link
Member

jasnell commented Oct 29, 2016

With exception to the DeprecationWarning pieces, yes I agree. process
warnings would be fairly easy to backport.

On Saturday, October 29, 2016, Rod Vagg notifications@github.com wrote:

This is a good candidate for backporting to v4 and v6, what think you
@nodejs/lts https://github.com/orgs/nodejs/teams/lts?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#9042 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAa2eYq50vBAGWiWlD241FCJwhWlhBbMks5q49RtgaJpZM4KUNXY
.

@rvagg
Copy link
Member

rvagg commented Oct 29, 2016

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
@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Mar 1, 2017
@jasnell
Copy link
Member

jasnell commented Mar 1, 2017

@evanlucas ... still want to pursue this?

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 1, 2017
@evanlucas
Copy link
Contributor Author

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 :]

@evanlucas evanlucas closed this Mar 17, 2017
@mscdex
Copy link
Contributor

mscdex commented Mar 17, 2017

Also, perhaps we could use a Symbol to make it less accessible since it seems like this is for internal use only?

@jasnell
Copy link
Member

jasnell commented Mar 20, 2017

I'll throw this on my todo list to look into

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants