Skip to content

Commit 7f02443

Browse files
toddselfrvagg
authored andcommitted
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: #2449 PR-URL: #2451 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 2d3f09b commit 7f02443

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/internal/repl.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
122122
}
123123
repl.history = repl.history.slice(-repl.historySize);
124124
} catch (err) {
125-
return ready(
125+
if (err.code !== 'ENOENT') {
126+
return ready(
126127
new Error(`Could not parse history data in ${oldHistoryPath}.`));
128+
}
127129
}
128130
}
129131

test/sequential/test-repl-persistent-history.js

+7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ const fixtures = path.join(common.testDir, 'fixtures');
6969
const historyFixturePath = path.join(fixtures, '.node_repl_history');
7070
const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history');
7171
const oldHistoryPath = path.join(fixtures, 'old-repl-history-file.json');
72+
const enoentHistoryPath = path.join(fixtures, 'enoent-repl-history-file.json');
7273

7374

7475
const tests = [{
7576
env: { NODE_REPL_HISTORY: '' },
7677
test: [UP],
7778
expected: [prompt, replDisabled, prompt]
7879
},
80+
{
81+
env: { NODE_REPL_HISTORY: '',
82+
NODE_REPL_HISTORY_FILE: enoentHistoryPath },
83+
test: [UP],
84+
expected: [prompt, replDisabled, prompt]
85+
},
7986
{
8087
env: { NODE_REPL_HISTORY: '',
8188
NODE_REPL_HISTORY_FILE: oldHistoryPath },

0 commit comments

Comments
 (0)