summaryrefslogtreecommitdiff
path: root/src/node_errors.cc
AgeCommit message (Collapse)Author
2019-11-28src: add more `can_call_into_js()` guardsAnna Henningsen
This is in preparation for running native `SetImmediate()` callbacks during shutdown. PR-URL: https://github.com/nodejs/node/pull/30666 Fixes: https://github.com/nodejs/node/issues/30643 Refs: https://github.com/nodejs/node/pull/30374 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-11-06src: make EndStartedProfilers an exit hookAnna Henningsen
Run `EndStartedProfilers` on Environment teardown. This is part of a series of changes to make embedding easier, by requiring fewer internal methods to build a fully functioning Node.js instance. PR-URL: https://github.com/nodejs/node/pull/30229 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
2019-10-22cli: add --trace-uncaught flagAnna Henningsen
Add a flag that makes Node.js print the stack trace at the time of *throwing* uncaught exceptions, rather than at the creation of the `Error` object, if there is any. This is disabled by default because it affects GC behavior. PR-URL: https://github.com/nodejs/node/pull/30025 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2019-09-24src: try showing stack traces when process._fatalException is not setJoyee Cheung
So that the stack trace of errors shown in internal code run during bootstrap (before process._fatalException is set) can be printed. PR-URL: https://github.com/nodejs/node/pull/29624 Refs: https://github.com/nodejs/node/pull/29593 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-09-24src: disconnect inspector before exiting out of fatal exceptionJoyee Cheung
So that coverage, .etc are properly written in case of a normal fatal exception. PR-URL: https://github.com/nodejs/node/pull/29611 Fixes: https://github.com/nodejs/node/issues/29570 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com>
2019-07-07src: allow fatal exceptions to be enhancedcjihrig
This commit allows fatal exceptions to be enhanced so that exceptions thrown from an unhandledException handler have the stack attached properly. PR-URL: https://github.com/nodejs/node/pull/28562 Fixes: https://github.com/nodejs/node/issues/28550 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-06-27process: split routines used to enhance fatal exception stack tracesJoyee Cheung
Previously the enhancement were done right after emitting `'uncaughtException'`, which meant by the time we knew the exception was fatal in C++, the error.stack had already been patched. This patch moves those routines to be called later during the fatal exception handling, and split them into two stages: before and after the inspector is notified by the invocation of `V8Inspector::exceptionThrown`. We now expand the stack to include additional informations about unhandled 'error' events before the inspector is notified, but delay the highlighting of the frames until after the inspector is notified, so that the ANSI escape sequences won't show up in the inspector console. PR-URL: https://github.com/nodejs/node/pull/28308 Fixes: https://github.com/nodejs/node/issues/28287 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2019-06-19src: refactor uncaught exception handlingJoyee Cheung
The C++ land `node::FatalException()` is not in fact fatal anymore. It gives the user a chance to handle the uncaught exception globally by listening to the `uncaughtException` event. This patch renames it to `TriggerUncaughtException` in C++ to avoid the confusion. In addition rename the JS land handler to `onGlobalUncaughtException` to reflect its purpose - we have to keep the alias `process._fatalException` and use that for now since it has been monkey-patchable in the user land. This patch also - Adds more comments to the global uncaught exception handling routine - Puts a few other C++ error handling functions into the `errors` namespace - Moves error-handling-related bindings to the `errors` binding. Refs: https://github.com/nodejs/node/commit/2b252acea47af3ebeac3d7e68277f015667264cc PR-URL: https://github.com/nodejs/node/pull/28257 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2019-06-12src: restore stdio on program exitBen Noordhuis
Record the state of the stdio file descriptors on start-up and restore them to that state on exit. This should prevent issues where node.js sometimes leaves stdio in raw or non-blocking mode. This is a reworked version of commit c2c9c0c3d3 from May 2018 that was reverted in commit 14dc17df38 from June 2018. The revert was a little light on details but I infer that the problem was caused by a missing call to `uv_tty_reset_mode()`. Apropos the NOLINT comments: cpplint doesn't understand do/while statements, it thinks they're while statements without a body. Fixes: https://github.com/nodejs/node/issues/14752 Fixes: https://github.com/nodejs/node/issues/21020 Original-PR-URL: https://github.com/nodejs/node/pull/20592 PR-URL: https://github.com/nodejs/node/pull/24260 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-06-09src: handle exceptions from ToDetailString()Anna Henningsen
These methods may fail if execution is terminating. PR-URL: https://github.com/nodejs/node/pull/28019 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-05-21src, lib: take control of prepareStackTraceGus Caplan
Refs https://crbug.com/v8/7848 PR-URL: https://github.com/nodejs/node/pull/23926 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-05-13src: remove util-inl.h from header filesSam Roberts
Its intended that *-inl.h header files are only included into the src files that call the inline methods. Explicitly include it into the files that need it. PR-URL: https://github.com/nodejs/node/pull/27631 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-04-26src: move OnMessage to node_errors.ccJoyee Cheung
Rename the per-isolate message listener to `PerIsolateMessageListener` and move it to `node_errors.cc` since it's part of the error handling process. It also creates an external reference so it needs to be exposed in `node_errors.h` for a snapshot builder to know. PR-URL: https://github.com/nodejs/node/pull/27304 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-04-17src: handle fatal error when Environment is not assigned to contextJoyee Cheung
Previously when an uncaught JS error is thrown before Environment was assigned to the context (e.g. a SyntaxError in a per-context script), it triggered an infinite recursion: 1. The error message listener `node::OnMessage()` triggered `node::FatalException()` 2. `node::FatalException()` attempted to get the Environment assigned to the context entered using `Environment::GetCurrent()` 3. `Environment::GetCurrent()` previously incorrectly accepted out-of-bound access with the length of the embedder data array as index, and called `context->GetAlignedPointerFromEmbedderData()` 4. The out-of-bound access in `GetAlignedPointerFromEmbedderData()` triggered a fatal error, which was handled by `node::FatalError()` 5. `node::FatalError()` called `Environment::GetCurrent()`, then we went back to 3. This patch fixes the incorrect guard in 3. When `Environment::GetCurrent()` returns nullptr (when Environment is not yet assigned to the context) in 2, it now prints the JS stack trace and crashes directly. PR-URL: https://github.com/nodejs/node/pull/27236 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-04-15process: add --unhandled-rejections flagRuben Bridgewater
This adds a flag to define the default behavior for unhandled rejections. Three modes exist: `none`, `warn` and `strict`. The first is going to silence all unhandled rejection warnings. The second behaves identical to the current default with the excetion that no deprecation warning will be printed and the last is going to throw an error for each unhandled rejection, just as regular exceptions do. It is possible to intercept those with the `uncaughtException` hook as with all other exceptions as well. This PR has no influence on the existing `unhandledRejection` hook. If that is used, it will continue to function as before. PR-URL: https://github.com/nodejs/node/pull/26599 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2019-03-30inspector: display error when ToggleAsyncHook failsJoyee Cheung
This patch refactors `AppendExceptionLine` and `PrintSyncTrace` to reuse the error formatting logic and use them to print uncaught error in ``ToggleAsyncHook` PR-URL: https://github.com/nodejs/node/pull/26859 Refs: https://github.com/nodejs/node/issues/26798 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-03-11process: refactor global.queueMicrotask()Joyee Cheung
- Lazy load `async_hooks` in the implementation - Rename `process/next_tick.js` to `process/task_queues.js` and move the implementation of `global.queueMicrotask()` there since these methods are conceptually related to each other. - Move the bindings used by `global.queueMicrotask()` into `node_task_queue.cc` instead of the generic `node_util.cc` - Use `defineOperation` to define `global.queueMicrotask()` PR-URL: https://github.com/nodejs/node/pull/26523 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-05src: refactor `Environment::GetCurrent(isolate)` usageAnna Henningsen
Do not require an explicit `HandleScope`, or the ability to create one, when using `Environment::GetCurrent()`. `isolate->InContext()` is used as an indicator that it is probably okay to create a `HandleScope`, see also the short discussion in https://github.com/nodejs/node/pull/25775#pullrequestreview-197371049. PR-URL: https://github.com/nodejs/node/pull/26376 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-03-03report: rename location to triggercjihrig
trigger more accurately describes the use of the field. Previously, location was just the name of the C++ function that called TriggerNodeReport(). PR-URL: https://github.com/nodejs/node/pull/26386 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-27src: apply clang-tidy rule modernize-deprecated-headersgengjiawen
PR-URL: https://github.com/nodejs/node/pull/26159 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-20report: simplify OnFatalError() handlingcjihrig
PR-URL: https://github.com/nodejs/node/pull/26191 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-02-17src: add debug CHECKs against empty handlesAnna Henningsen
These checks were useful while investigating other issues; using empty `Local<>`s can be very un-debuggable, because that typically does not lead to assertions with debugging information but rather crashes based on accessing invalid memory. PR-URL: https://github.com/nodejs/node/pull/26125 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-02-03src: handle errors while printing error objectsAnna Henningsen
Handle situations where accessing `.name` or `.stack` on an object fails. Fixes: https://github.com/nodejs/node/issues/25718 PR-URL: https://github.com/nodejs/node/pull/25834 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-02-03src: use struct as arguments to node::AssertAnna Henningsen
This just makes the code a bit more obvious (subjectively). PR-URL: https://github.com/nodejs/node/pull/25869 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2019-02-01src: move public C++ APIs into src/api/*.ccJoyee Cheung
This patch moves most of the public C++ APIs into src/api/*.cc so that it's easier to tell that we need to be careful about the compatibility of these code. Some APIs, like `node::LoadEnvironmet()`, `node::Start()` and `node::Init()` still stay in `node.cc` because they are still very specific to our use cases and do not work quite well yet for embedders anyway - we could not even manage to write cctest for them at the moment. PR-URL: https://github.com/nodejs/node/pull/25541 Reviewed-By: Gus Caplan <me@gus.host>
2019-01-30src: add handle scope to `OnFatalError()`Anna Henningsen
For the report generation, we use `Environment::GetCurrent(isolate)` which uses `isolate->GetCurrentContext()` under the hood, thus allocates a handle. Without a `HandleScope`, this is invalid. This might not strictly be allowed inside of `OnFatalError()`, but it won’t make anything worse either. PR-URL: https://github.com/nodejs/node/pull/25775 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2019-01-24src: remove unnecessary `filename` variableAnna Henningsen
PR-URL: https://github.com/nodejs/node/pull/25610 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2019-01-18src: merge into coreGireesh Punathil
Make node-report part of core runtime because: 1. When enabled, node-report significantly helps root cause various types of problems, including support issues sent to the various repos of the Node.js organization. 2. The requirement of explicitly adding the dependency to node-report in user applications often represents a blocker to adoption. Major deviation from the module version of the node-report is that the report is generated in JSON format, as opposed to human readable text. No new functionalities have been added, changes that are required for melding it as a built-in capability has been affected on the module version of node-report (https://github.com/nodejs/node-report) Co-authored-by: Bidisha Pyne <bidipyne@in.ibm.com> Co-authored-by: Howard Hellyer <hhellyer@uk.ibm.com> Co-authored-by: Jeremiah Senkpiel <fishrock123@rocketmail.com> Co-authored-by: Julian Alimin <dmastag@yahoo.com> Co-authored-by: Lakshmi Swetha Gopireddy <lakshmigopireddy@in.ibm.com> Co-authored-by: Manusaporn Treerungroj <m.treerungroj@gmail.com> Co-authored-by: Michael Dawson <michael_dawson@ca.ibm.com> Co-authored-by: Richard Chamberlain <richard_chamberlain@uk.ibm.com> Co-authored-by: Richard Lau <riclau@uk.ibm.com> Co-authored-by: Sam Roberts <vieuxtech@gmail.com> Co-authored-by: Vipin Menon <vipinmv1@in.ibm.com> PR-URL: https://github.com/nodejs/node/pull/22712 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <Michael_Dawson@ca.ibm.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
2019-01-16src: call `Environment::Exit()` for fatal exceptionsAnna Henningsen
Call `Environment::Exit()` rather than the process-wide `exit()` function, since JS exceptions generally only affect the current JS engine instance. PR-URL: https://github.com/nodejs/node/pull/25472 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-01-14src: move node::errno_string into node_errors.h/ccJoyee Cheung
Move `node::errno_string` into node_errors.h/cc and move it into the `node:errors` namespace to reduce the size of the header. It's not on any performance-critical code path so does not need to be inlined. PR-URL: https://github.com/nodejs/node/pull/25396 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-01-08src: move per-process global variables into node::per_processJoyee Cheung
So that it's easier to tell whether we are manipulating per-process global states that may need to be treated with care to avoid races. Also added comments about these variables and moved some of them to a more suitable compilation unit: - Move `v8_initialized` to `util.h` since it's only used in `util.cc` and `node.cc` - Rename `process_mutex` to `tty_mutex` and move it into `node_errors.cc` since that's the only place it's used to guard the tty. - Move `per_process_opts_mutex` and `per_process_opts` into `node_options.h` and rename them to `per_process::cli_options[_mutex]` - Rename `node_isolate[_mutex]` to `per_process::main_isolate[_mutex]` PR-URL: https://github.com/nodejs/node/pull/25302 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-12-31src: ignore termination exceptions in fatal TryCatchAnna Henningsen
We don’t want these to terminate the process in case of Worker threads receiving a termination exception, rather than a “real one”. PR-URL: https://github.com/nodejs/node/pull/25141 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
2018-12-03src: use custom TryCatch subclassGus Caplan
PR-URL: https://github.com/nodejs/node/pull/24751 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-11-11src: fix v8 compiler warnings in srcDaniel Bevenius
This commit changes the code to use the maybe version. PR-URL: https://github.com/nodejs/node/pull/24246 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
2018-11-06src: move error handling code into node_errors.ccJoyee Cheung
Move the following code into a new node_errors.cc file and declare them in node_errors.h for clarity and make it possible to include them with node_errors.h. - AppendExceptionLine() - DecorateErrorStack() - FatalError() - OnFatalError() - PrintErrorString() - FatalException() - ReportException() - FatalTryCatch And move the following definitions (declared elsewhere than node_errors.h) to node_errors.cc: - Abort() (in util.h) - Assert() (in util.h) PR-URL: https://github.com/nodejs/node/pull/24058 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>