From 0d89d4d284b3ef36a3be5557e5f5ff75436d5f71 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 26 Oct 2017 22:04:07 -0700 Subject: [PATCH 1/2] src: use internal/errors for startSigintWatchdog Move the throw out of c++ and into js using internal/errors --- doc/api/errors.md | 8 ++++++++ lib/internal/errors.js | 1 + lib/repl.js | 3 ++- src/node_util.cc | 5 +---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 6d8eed949203e3..7895990004cec9 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1247,6 +1247,14 @@ range. Used by the `REPL` module when it cannot parse data from the REPL history file. + +### ERR_REPL_STARTSIGINTWATCHDOG_FAILED + +The `SigintWatchdog` is an internal utility used by the `repl` module to +monitor for interupt (`SIGINT`) signals received by the process. If this +utility cannot be started, the `repl` will not function correctly, so an +error is thrown. + ### ERR_REQUIRE_ESM diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 6f056b1ef8bec1..df5ba781aba246 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -310,6 +310,7 @@ E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported'); E('ERR_OUTOFMEMORY', 'Out of memory'); E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range'); E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s'); +E('ERR_REPL_STARTSIGINTWATCHDOG_FAILED', 'startSigintWatchdog Failed'); E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s'); E('ERR_SERVER_ALREADY_LISTEN', 'Listen method has been called more than once without closing.'); diff --git a/lib/repl.js b/lib/repl.js index d4b95bf3a67f45..52d7f0265915ab 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -227,7 +227,8 @@ function REPLServer(prompt, if (self.breakEvalOnSigint) { // Start the SIGINT watchdog before entering raw mode so that a very // quick Ctrl+C doesn't lead to aborting the process completely. - utilBinding.startSigintWatchdog(); + if (!utilBinding.startSigintWatchdog()) + throw new errors.Error('ERR_REPL_STARTSIGINTWATCHDOG_FAILED'); previouslyInRawMode = self._setRawMode(false); } diff --git a/src/node_util.cc b/src/node_util.cc index cf26eca692e6ed..fa30ae447220aa 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -135,10 +135,7 @@ static void SetHiddenValue(const FunctionCallbackInfo& args) { void StartSigintWatchdog(const FunctionCallbackInfo& args) { int ret = SigintWatchdogHelper::GetInstance()->Start(); - if (ret != 0) { - Environment* env = Environment::GetCurrent(args); - env->ThrowErrnoException(ret, "StartSigintWatchdog"); - } + args.GetReturnValue().Set(ret == 0); } From ec5f9c4a9c4f721c38267c8e005a14dc13560f4a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 29 Oct 2017 17:54:23 -0700 Subject: [PATCH 2/2] [Squash] nit --- doc/api/errors.md | 13 +++++-------- lib/internal/errors.js | 2 +- lib/repl.js | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 7895990004cec9..d0e2512c04fff2 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -615,6 +615,11 @@ Used when attempting to perform an operation outside the bounds of a `Buffer`. Used when an attempt has been made to create a `Buffer` larger than the maximum allowed size. + +### ERR_CANNOT_WATCH_SIGINT + +Used when Node.js is unable to watch for the `SIGINT` signal. + ### ERR_CHILD_CLOSED_BEFORE_REPLY @@ -1247,14 +1252,6 @@ range. Used by the `REPL` module when it cannot parse data from the REPL history file. - -### ERR_REPL_STARTSIGINTWATCHDOG_FAILED - -The `SigintWatchdog` is an internal utility used by the `repl` module to -monitor for interupt (`SIGINT`) signals received by the process. If this -utility cannot be started, the `repl` will not function correctly, so an -error is thrown. - ### ERR_REQUIRE_ESM diff --git a/lib/internal/errors.js b/lib/internal/errors.js index df5ba781aba246..8171216fbf8fbb 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -151,6 +151,7 @@ E('ERR_ASYNC_TYPE', (s) => `Invalid name for async "type": ${s}`); E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds); E('ERR_BUFFER_TOO_LARGE', `Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes`); +E('ERR_CANNOT_WATCH_SIGINT', 'Cannot watch for SIGINT signals'); E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received'); E('ERR_CONSOLE_WRITABLE_STREAM', 'Console expects a writable stream instance for %s'); @@ -310,7 +311,6 @@ E('ERR_NO_LONGER_SUPPORTED', '%s is no longer supported'); E('ERR_OUTOFMEMORY', 'Out of memory'); E('ERR_OUT_OF_RANGE', 'The "%s" argument is out of range'); E('ERR_PARSE_HISTORY_DATA', 'Could not parse history data in %s'); -E('ERR_REPL_STARTSIGINTWATCHDOG_FAILED', 'startSigintWatchdog Failed'); E('ERR_REQUIRE_ESM', 'Must use import to load ES Module: %s'); E('ERR_SERVER_ALREADY_LISTEN', 'Listen method has been called more than once without closing.'); diff --git a/lib/repl.js b/lib/repl.js index 52d7f0265915ab..73de1797969a6b 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -228,7 +228,7 @@ function REPLServer(prompt, // Start the SIGINT watchdog before entering raw mode so that a very // quick Ctrl+C doesn't lead to aborting the process completely. if (!utilBinding.startSigintWatchdog()) - throw new errors.Error('ERR_REPL_STARTSIGINTWATCHDOG_FAILED'); + throw new errors.Error('ERR_CANNOT_WATCH_SIGINT'); previouslyInRawMode = self._setRawMode(false); }