Skip to content

repl: propagate setupHistory callback errors#61722

Closed
ThanhNguyxn wants to merge 1 commit intonodejs:mainfrom
ThanhNguyxn:fix-repl-history-error-propagation
Closed

repl: propagate setupHistory callback errors#61722
ThanhNguyxn wants to merge 1 commit intonodejs:mainfrom
ThanhNguyxn:fix-repl-history-error-propagation

Conversation

@ThanhNguyxn
Copy link

Description

Fixes #60837

Errors thrown within the onReadyCallback passed to setupHistory() were being silently discarded when called from async contexts (event listeners and catch handlers).

This was a regression introduced in #58225.

Changes

  • Wrapped callback invocations in try-catch blocks at two locations in lib/internal/repl/history.js:

    1. Line 324-328: Inside the 'flushHistory' event listener
    2. Line 352-356: Inside the kHandleHistoryInitError method
  • Use process.nextTick(() => { throw err; }) to properly propagate errors to the event loop, ensuring callback errors are not silently swallowed.

Root Cause Analysis

In ReplHistory.initialize(), when onReadyCallback is invoked:

  • Inside event listeners (line 324)
  • Inside catch handlers (line 352)

Any errors thrown by the callback were being caught by the surrounding async context and silently discarded. The fix ensures these errors are re-thrown via process.nextTick to properly surface them.

Testing

Verified that callback errors are now properly propagated and cause uncaught exception handlers to fire as expected.

Errors thrown within the onReadyCallback passed to setupHistory()
were being silently discarded when called from async contexts
(event listeners and catch handlers). This fix wraps callback
invocations in try-catch and uses process.nextTick to properly
propagate errors.

Fixes: nodejs#60837
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem. labels Feb 7, 2026
@ThanhNguyxn
Copy link
Author

Closing as duplicate of #60903

@ThanhNguyxn ThanhNguyxn closed this Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. repl Issues and PRs related to the REPL subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replServer.setupHistory() silently discards callback errors since v24.2.0

2 participants