Skip to content

Commit

Permalink
repl: display error message when loading directory
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
princejwesley authored and cjihrig committed Dec 15, 2015
1 parent 9271f0e commit 5f5d325
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ function defineDefaultCommands(repl) {
self.write(line + '\n');
}
});
} else {
this.outputStream.write('Failed to load:' + file +
' is not a valid file\n');
}
} catch (e) {
this.outputStream.write('Failed to load:' + file + '\n');
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-repl-.save.load.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ putIn.write = function(data) {
};
putIn.run(['.load ' + loadFile]);

// throw error on loading directory
loadFile = common.tmpDir;
putIn.write = function(data) {
assert.equal(data, 'Failed to load:' + loadFile + ' is not a valid file\n');
putIn.write = function() {};
};
putIn.run(['.load ' + loadFile]);

// clear the REPL
putIn.run(['.clear']);

Expand Down

0 comments on commit 5f5d325

Please sign in to comment.