Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 459b106

Browse filesBrowse files
committed
repl: attach location info to syntax errors
Currently, when a file with a syntax error is imported in the REPL, no information is provided on the error's location. This commit adds the error's location to the stack trace. Refs: #2762 Refs: #3411 Refs: #3784 PR-URL: #4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 8ca412b commit 459b106
Copy full SHA for 459b106

File tree

Expand file treeCollapse file tree

2 files changed

+40
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+40
-0
lines changed
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ function REPLServer(prompt,
274274
self._domain.on('error', function(e) {
275275
debug('domain error');
276276
const top = replMap.get(self);
277+
util.decorateErrorStack(e);
277278
top.outputStream.write((e.stack || e) + '\n');
278279
top.lineParser.reset();
279280
top.bufferedCommand = '';
Collapse file
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const path = require('path');
6+
const repl = require('repl');
7+
const util = require('util');
8+
let found = false;
9+
10+
process.on('exit', () => {
11+
assert.strictEqual(found, true);
12+
});
13+
14+
// A stream to push an array into a REPL
15+
function ArrayStream() {
16+
this.run = function(data) {
17+
data.forEach(line => {
18+
this.emit('data', line + '\n');
19+
});
20+
};
21+
}
22+
util.inherits(ArrayStream, require('stream').Stream);
23+
ArrayStream.prototype.readable = true;
24+
ArrayStream.prototype.writable = true;
25+
ArrayStream.prototype.resume = function() {};
26+
ArrayStream.prototype.write = function(output) {
27+
if (/var foo bar;/.test(output))
28+
found = true;
29+
};
30+
31+
const putIn = new ArrayStream();
32+
const testMe = repl.start('', putIn);
33+
let file = path.resolve(__dirname, '../fixtures/syntax/bad_syntax');
34+
35+
if (common.isWindows)
36+
file = file.replace(/\\/g, '\\\\');
37+
38+
putIn.run(['.clear']);
39+
putIn.run([`require('${file}');`]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.