Skip to content

Commit

Permalink
process: add CLI opt to hide experimental warnings
Browse files Browse the repository at this point in the history
Adds a command line option to supress experimental warnings. Currently
this cannot be accomplished without supressing all warnings (by using
the --no-warnings option). However, once this option is enabled, a user
can miss out on essential warnings as this supresses all warnings.
This commit adds the --no-experimental-warnings command line option to
allow users to ignore warnings they will expect while still being able
to monitor unexpected warnings.

Fixes: nodejs#30810
  • Loading branch information
codeman869 committed Dec 23, 2019
1 parent 38a593b commit 0693a79
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ added: v0.8.0

Silence deprecation warnings.

### `--no-experimental-warnings`
<!-- YAML
added: REPLACEME
-->

Silence all experimental process warnings. These are emitted when using
features which are considered experimental.

### `--no-force-async-hooks-checks`
<!-- YAML
added: v9.0.0
Expand Down Expand Up @@ -1111,6 +1119,7 @@ Node.js options that are allowed are:
* `--max-http-header-size`
* `--napi-modules`
* `--no-deprecation`
* `--no-experimental-warnings`
* `--no-force-async-hooks-checks`
* `--no-warnings`
* `--openssl-config`
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ function slowCases(enc) {
}

function emitExperimentalWarning(feature) {
const { getOptionValue } = require('internal/options');
if (getOptionValue('--no-experimental-warnings')) return;
if (experimentalWarnings.has(feature)) return;
const msg = `${feature} is an experimental feature. This feature could ` +
'change at any time';
Expand Down
4 changes: 4 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"silence all process warnings",
&EnvironmentOptions::no_warnings,
kAllowedInEnvironment);
AddOption("--no-experimental-warnings",
"silence all experimental process warnings",
&EnvironmentOptions::no_experimental_warnings,
kAllowedInEnvironment);
AddOption("--force-context-aware",
"disable loading non-context-aware addons",
&EnvironmentOptions::force_context_aware,
Expand Down
1 change: 1 addition & 0 deletions src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class EnvironmentOptions : public Options {
bool no_deprecation = false;
bool no_force_async_hooks_checks = false;
bool no_warnings = false;
bool no_experimental_warnings = false;
bool force_context_aware = false;
bool pending_deprecation = false;
bool preserve_symlinks = false;
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-process-no-emit-experimental-warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Flags: --no-experimental-warnings --expose-internals
'use strict';
// Test supressing experimental warnings.
const common = require('../common');
const { hijackStderr,
restoreStderr
} = require('../common/hijackstdio');
const { emitExperimentalWarning } = require('internal/util');

function test() {
hijackStderr(common.mustNotCall('stderr.write must not be called'));
emitExperimentalWarning('testExperimentalWarning');
restoreStderr();
}

test();

0 comments on commit 0693a79

Please sign in to comment.