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. Its good to display error message for
this scenario.

Before:
  > .load /Users/princejohnwesley/Projects/Playground/Node
  >

After:
  > .load /Users/princejohnwesley/Projects/Playground/Node
    Failed to load:/Users/princejohnwesley/Projects/Playground/Node is not a valid file
  >
  • Loading branch information
princejwesley committed Dec 10, 2015
1 parent 84dea1b commit 8a6db50
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 8a6db50

Please sign in to comment.