From aad6b9f0ebf79cb4f80a9b4be7c05e27a5d9489d Mon Sep 17 00:00:00 2001 From: Prince J Wesley Date: Sun, 6 Dec 2015 14:46:52 +0530 Subject: [PATCH] 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 Reviewed-By: Ben Noordhuis Reviewed-By: Minwoo Jung --- lib/repl.js | 3 +++ test/parallel/test-repl-.save.load.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/repl.js b/lib/repl.js index 7b130ca3edc02f..8e81e6134381e8 100644 --- a/lib/repl.js +++ b/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'); diff --git a/test/parallel/test-repl-.save.load.js b/test/parallel/test-repl-.save.load.js index 2b9ceed4db633c..c71b383bcd7409 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/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']);