Skip to content

Commit aad6b9f

Browse files
princejwesleyJungMinu
authored andcommitted
repl: display error message when loading directory
When loading directory instead of file, no error message is displayed. It's good to display error message for this scenario. PR-URL: #4170 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 67e1819 commit aad6b9f

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)