From d4806675a64c5714305741651ced8c925a2a9f1c 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 ef641a89c4012e..4fe50f3979e68f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -1059,6 +1059,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 f63b61bf41e15b..56566719926519 100644 --- a/test/parallel/test-repl-.save.load.js +++ b/test/parallel/test-repl-.save.load.js @@ -76,6 +76,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']);