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

doc: changes to process warning documentation #9590

Merged
merged 2 commits into from
Nov 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 7 additions & 47 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,50 +312,6 @@ $ node --no-warnings
The `--trace-warnings` command-line option can be used to have the default
console output for warnings include the full stack trace of the warning.

#### Emitting custom warnings

The [`process.emitWarning()`][process_emit_warning] method can be used to issue
custom or application specific warnings.

```js
// Emit a warning using a string...
process.emitWarning('Something happened!');
// Prints: (node 12345) Warning: Something happened!

// Emit a warning using an object...
process.emitWarning('Something Happened!', 'CustomWarning');
// Prints: (node 12345) CustomWarning: Something happened!

// Emit a warning using a custom Error object...
class CustomWarning extends Error {
constructor(message) {
super(message);
this.name = 'CustomWarning';
Error.captureStackTrace(this, CustomWarning);
}
}
const myWarning = new CustomWarning('Something happened!');
process.emitWarning(myWarning);
// Prints: (node 12345) CustomWarning: Something happened!
```

#### Emitting custom deprecation warnings

Custom deprecation warnings can be emitted by setting the `name` of a custom
warning to `DeprecationWarning`. For instance:

```js
process.emitWarning('This API is deprecated', 'DeprecationWarning');
```

Or,

```js
const err = new Error('This API is deprecated');
err.name = 'DeprecationWarning';
process.emitWarning(err);
```

Launching Node.js using the `--throw-deprecation` command line flag will
cause custom deprecation warnings to be thrown as exceptions.

Expand All @@ -368,6 +324,11 @@ of the custom deprecation.
The `*-deprecation` command line flags only affect warnings that use the name
`DeprecationWarning`.

#### Emitting custom warnings

See the [`process.emitWarning()`][process_emit_warning] method for issuing
custom or application-specific warnings.

### Signal Events

<!--type=event-->
Expand Down Expand Up @@ -821,11 +782,10 @@ so, it is recommended to place the `emitWarning()` behind a simple boolean
flag as illustrated in the example below:

```js
var warned = false;
function emitMyWarning() {
if (!warned) {
if (!emitMyWarning.warned) {
emitMyWarning.warned = true;
process.emitWarning('Only warn once!');
warned = true;
}
}
emitMyWarning();
Expand Down