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 JungMinu committed Dec 11, 2015
1 parent 67e1819 commit aad6b9f
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 aad6b9f

Please sign in to comment.