From ee94671d0cde38260388bfa6f60ec365c1044350 Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Wed, 19 Aug 2015 15:44:20 -0700 Subject: [PATCH] repl: don't throw ENOENT on NODE_REPL_HISTORY_FILE Fixes: node/nodejs#2449. If you have no history file written to disk, but the environment variable set, `fs.readFileSync` will throw an ENOENT error, but there's nothing to convert. The converter should ignore ENOENT on that `fs.readFileSync` call --- lib/internal/repl.js | 4 +++- test/sequential/test-repl-persistent-history.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/internal/repl.js b/lib/internal/repl.js index 75909f72e2415e..b2c74e179c59d0 100644 --- a/lib/internal/repl.js +++ b/lib/internal/repl.js @@ -122,8 +122,10 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) { } repl.history = repl.history.slice(-repl.historySize); } catch (err) { - return ready( + if (err.code !== 'ENOENT') { + return ready( new Error(`Could not parse history data in ${oldHistoryPath}.`)); + } } } diff --git a/test/sequential/test-repl-persistent-history.js b/test/sequential/test-repl-persistent-history.js index 8d550f6c1d7124..ef433912da5a65 100644 --- a/test/sequential/test-repl-persistent-history.js +++ b/test/sequential/test-repl-persistent-history.js @@ -69,6 +69,7 @@ const fixtures = path.join(common.testDir, 'fixtures'); const historyFixturePath = path.join(fixtures, '.node_repl_history'); const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history'); const oldHistoryPath = path.join(fixtures, 'old-repl-history-file.json'); +const enoentHistoryPath = path.join(fixtures, 'enoent-repl-history-file.json'); const tests = [{ @@ -76,6 +77,12 @@ const tests = [{ test: [UP], expected: [prompt, replDisabled, prompt] }, +{ + env: { NODE_REPL_HISTORY: '', + NODE_REPL_HISTORY_FILE: enoentHistoryPath }, + test: [UP], + expected: [prompt, replDisabled, prompt] +}, { env: { NODE_REPL_HISTORY: '', NODE_REPL_HISTORY_FILE: oldHistoryPath },