Skip to content

Commit

Permalink
[squash] switch to error
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Feb 26, 2018
1 parent fb8b01f commit 1867690
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions doc/api/repl.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ global or scoped variable, the input `fs` will be evaluated on-demand as
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/18919
description: Added `_err` support.
description: Added `_error` support.
-->

The default evaluator will, by default, assign the result of the most recently
Expand All @@ -168,14 +168,14 @@ Expression assignment to _ now disabled.
4
```

Similarly, `_err` will refer to the last seen error, if there was any.
Explicitly setting `_err` to a value will disable this behavior.
Similarly, `_error` will refer to the last seen error, if there was any.
Explicitly setting `_error` to a value will disable this behavior.

<!-- eslint-skip -->
```js
> throw new Error('foo');
Error: foo
> _err.message
> _error.message
'foo'
```

Expand Down
4 changes: 2 additions & 2 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,15 +816,15 @@ REPLServer.prototype.resetContext = function() {
}
});

Object.defineProperty(this.context, '_err', {
Object.defineProperty(this.context, '_error', {
configurable: true,
get: () => this.lastError,
set: (value) => {
this.lastError = value;
if (!this.underscoreErrAssigned) {
this.underscoreErrAssigned = true;
this.outputStream.write(
'Expression assignment to _err now disabled.\n');
'Expression assignment to _error now disabled.\n');
}
}
});
Expand Down
22 changes: 11 additions & 11 deletions test/parallel/test-repl-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ function testResetContextGlobal() {
function testError() {
const r = initRepl(repl.REPL_MODE_STRICT);

r.write(`_err; // initial value undefined
r.write(`_error; // initial value undefined
throw new Error('foo'); // throws error
_err; // shows error
_error; // shows error
fs.readdirSync('/nonexistent?'); // throws error, sync
_err.code; // shows error code
_err.syscall; // shows error syscall
_error.code; // shows error code
_error.syscall; // shows error syscall
setImmediate(() => { throw new Error('baz'); }); undefined;
// throws error, async
`);
Expand All @@ -172,7 +172,7 @@ function testError() {
const expectedLines = [
'undefined',

// The error, both from the original throw and the `_err` echo.
// The error, both from the original throw and the `_error` echo.
'Error: foo',
'Error: foo',

Expand Down Expand Up @@ -203,17 +203,17 @@ function testError() {
}
assert.strictEqual(expectedLines.length, 0);

// Reset output, check that '_err' is the asynchronously caught error.
// Reset output, check that '_error' is the asynchronously caught error.
r.output.accum = '';
r.write(`_err.message // show the message
_err = 0; // disable auto-assignment
throw new Error('quux'); // new error
_err; // should not see the new error
r.write(`_error.message // show the message
_error = 0; // disable auto-assignment
throw new Error('quux'); // new error
_error; // should not see the new error
`);

assertOutput(r.output, [
"'baz'",
'Expression assignment to _err now disabled.',
'Expression assignment to _error now disabled.',
'0',
'Error: quux',
'0'
Expand Down

0 comments on commit 1867690

Please sign in to comment.