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 <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
  • Loading branch information
princejwesley authored and Myles Borins committed Jan 19, 2016
1 parent 06113b8 commit d480667
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 @@ -1059,6 +1059,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 @@ -76,6 +76,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 d480667

Please sign in to comment.