Browse Source

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: https://github.com/nodejs/node/pull/4170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
v5.x
Prince J Wesley 9 years ago
committed by cjihrig
parent
commit
5f5d325030
  1. 3
      lib/repl.js
  2. 8
      test/parallel/test-repl-.save.load.js

3
lib/repl.js

@ -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');

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

@ -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']);

Loading…
Cancel
Save