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

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎lib/internal/repl.js‎

Lines changed: 3 additions & 1 deletion
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-
returnready(
125+
if(err.code!=='ENOENT'){
126+
returnready(
126127
newError(`Could not parse history data in ${oldHistoryPath}.`));
128+
}
127129
}
128130
}
129131

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ const fixtures = path.join(common.testDir, 'fixtures');
6969
consthistoryFixturePath=path.join(fixtures,'.node_repl_history');
7070
consthistoryPath=path.join(common.tmpDir,'.fixture_copy_repl_history');
7171
constoldHistoryPath=path.join(fixtures,'old-repl-history-file.json');
72+
constenoentHistoryPath=path.join(fixtures,'enoent-repl-history-file.json');
7273

7374

7475
consttests=[{
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)