Skip to content

Node REPL does not honor uncaughtException listeners #19998

Description

@AyushG3112

REPL commands

$ node
> process.on('uncaughtException', (err) => console.log('caught' + err));
> throw 'hi';

OUTPUT :

Thrown: hi

Running process.hasUncaughtExceptionCaptureCallback() in the REPL console outputs true, so it is understandable why the listener isn't called.

However

> process.setUncaughtExceptionCaptureCallback(null);

throws the Error:

Error [ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE]: The `domain` module is in use, which is mutually exclusive with calling process.setUncaughtExceptionCaptureCallback()
    at process.setUncaughtExceptionCaptureCallback (domain.js:97:15)
    at repl:1:9
    at Script.runInThisContext (vm.js:91:20)
    at REPLServer.defaultEval (repl.js:311:29)
    at bound (domain.js:396:14)
    at REPLServer.runBound [as eval] (domain.js:409:12)
    at REPLServer.onLine (repl.js:609:10)
    at REPLServer.emit (events.js:187:15)
    at REPLServer.emit (domain.js:442:20)
    at REPLServer.Interface._onLine (readline.js:285:10)
----------------------------------------
Error: require(`domain`) at this point
    at domain.js:93:28
    at NativeModule.compile (internal/bootstrap/loaders.js:209:7)
    at NativeModule.require (internal/bootstrap/loaders.js:137:18)
    at repl.js:63:16
    at NativeModule.compile (internal/bootstrap/loaders.js:209:7)
    at NativeModule.require (internal/bootstrap/loaders.js:137:18)
    at internal/repl.js:4:14
    at NativeModule.compile (internal/bootstrap/loaders.js:209:7)
    at Function.NativeModule.require (internal/bootstrap/loaders.js:137:18)
    at startup (internal/bootstrap/node.js:240:40)

I could not find any documentation of this behaviour for the Node REPL.

Is this a bug, or is this a desired behaviour which has to be documented?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to Node.js documentation.domainIssues and PRs related to the domain subsystem.replIssues and PRs related to the REPL subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions