From 5f5d3250301ef79e413f71264fd76d14b65777c2 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 f15380e67f..76c7487b7b 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 2b9ceed4db..c71b383bcd 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']);