repl: dont throw ENOENT on NODE_REPL_HISTORY_FILE

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.

Fixes: https://github.com/nodejs/node/issues/2449
PR-URL: https://github.com/nodejs/node/pull/2451
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
pull/2451/merge
Todd Kennedy 2015-08-19 15:44:20 -07:00 committed by Jeremiah Senkpiel
parent 291b310e21
commit 3849750a09
2 changed files with 10 additions and 1 deletions

View File

@ -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}.`));
}
}
}

View File

@ -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 },