GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: don't crash if cannot open history file · nodejs/node@5073da0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • repl.js
  • test/sequential
    • test-repl-persistent-history.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/repl.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl.js
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ function setupHistory(repl, historyPath, oldHistoryPath, ready) {
9292

9393
function oninit(err, hnd) {
9494
if (err) {
95-
return ready(err);
95+
// Cannot open history file.
96+
// Don't crash, just don't persist history.
97+
repl._writeToOutput('\nError: Could not open history file.\n' +
98+
'REPL session history will not be persisted.\n');
99+
repl._refreshLine();
100+
debug(err.stack);
101+
102+
repl._historyPrev = _replHistoryMessage;
103+
repl.resume();
104+
return ready(null, repl);
96105
}
97106
fs.close(hnd, onclose);
98107
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-repl-persistent-history.js
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ const convertMsg = '\nConverting old JSON repl history to line-separated ' +
6464
path.join(common.tmpDir, '.node_repl_history') + '.\n';
6565
const homedirErr = '\nError: Could not get the home directory.\n' +
6666
'REPL session history will not be persisted.\n';
67+
const replFailedRead = '\nError: Could not open history file.\n' +
68+
'REPL session history will not be persisted.\n';
6769
// File paths
6870
const fixtures = path.join(common.testDir, 'fixtures');
6971
const historyFixturePath = path.join(fixtures, '.node_repl_history');
7072
const historyPath = path.join(common.tmpDir, '.fixture_copy_repl_history');
73+
const historyPathFail = path.join(common.tmpDir, '.node_repl\u0000_history');
7174
const oldHistoryPath = path.join(fixtures, 'old-repl-history-file.json');
7275
const enoentHistoryPath = path.join(fixtures, 'enoent-repl-history-file.json');
7376
const defaultHistoryPath = path.join(common.tmpDir, '.node_repl_history');
@@ -147,6 +150,12 @@ const tests = [{
147150
test: [UP, UP, UP, CLEAR],
148151
expected: [prompt, convertMsg, prompt, prompt + '\'=^.^=\'', prompt]
149152
},
153+
{
154+
env: { NODE_REPL_HISTORY: historyPathFail,
155+
NODE_REPL_HISTORY_SIZE: 1 },
156+
test: [UP],
157+
expected: [prompt, replFailedRead, prompt, replDisabled, prompt]
158+
},
150159
{ // Make sure this is always the last test, since we change os.homedir()
151160
before: function mockHomedirFailure() {
152161
// Mock os.homedir() failure

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.