Skip to content

Commit d480667

Browse files
princejwesleyMyles Borins
authored and
Myles Borins
committed
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 06113b8 commit d480667

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/repl.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,9 @@ function defineDefaultCommands(repl) {
10591059
self.write(line + '\n');
10601060
}
10611061
});
1062+
} else {
1063+
this.outputStream.write('Failed to load:' + file +
1064+
' is not a valid file\n');
10621065
}
10631066
} catch (e) {
10641067
this.outputStream.write('Failed to load:' + file + '\n');

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ putIn.write = function(data) {
7676
};
7777
putIn.run(['.load ' + loadFile]);
7878

79+
// throw error on loading directory
80+
loadFile = common.tmpDir;
81+
putIn.write = function(data) {
82+
assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\n');
83+
putIn.write = function() {};
84+
};
85+
putIn.run(['.load ' + loadFile]);
86+
7987
// clear the REPL
8088
putIn.run(['.clear']);
8189

0 commit comments

Comments
 (0)