Skip to content

Commit 8a6db50

Browse files
committed
repl: display error message when loading directory
When loading directory instead of file, no error message is displayed. Its good to display error message for this scenario. Before: > .load /Users/princejohnwesley/Projects/Playground/Node > After: > .load /Users/princejohnwesley/Projects/Playground/Node Failed to load:/Users/princejohnwesley/Projects/Playground/Node is not a valid file >
1 parent 84dea1b commit 8a6db50

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/repl.js

+3
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ function defineDefaultCommands(repl) {
10821082
self.write(line + '\n');
10831083
}
10841084
});
1085+
} else {
1086+
this.outputStream.write('Failed to load:' + file +
1087+
' is not a valid file\n');
10851088
}
10861089
} catch (e) {
10871090
this.outputStream.write('Failed to load:' + file + '\n');

test/parallel/test-repl-.save.load.js

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ putIn.write = function(data) {
6161
};
6262
putIn.run(['.load ' + loadFile]);
6363

64+
// throw error on loading directory
65+
loadFile = common.tmpDir;
66+
putIn.write = function(data) {
67+
assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\n');
68+
putIn.write = function() {};
69+
};
70+
putIn.run(['.load ' + loadFile]);
71+
6472
// clear the REPL
6573
putIn.run(['.clear']);
6674

0 commit comments

Comments
 (0)