Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2acb57b

Browse filesBrowse files
legendecastargos
authored andcommitted
src: mark fatal error functions as noreturn
OnFatalError and OOMErrorHandler will not return control flow to the calling function. node::FatalError is an alias of node::OnFatalError. Replace all the callsites with node::OnFatalError instead. PR-URL: #47695 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
1 parent f88132f commit 2acb57b
Copy full SHA for 2acb57b

File tree

Expand file treeCollapse file tree

7 files changed

+14
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+14
-20
lines changed
Open diff view settings
Collapse file

‎src/api/environment.cc‎

Copy file name to clipboardExpand all lines: src/api/environment.cc
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,7 @@ Maybe<bool> InitializeContextRuntime(Local<Context> context) {
726726
}
727727
} else if (per_process::cli_options->disable_proto != "") {
728728
// Validated in ProcessGlobalArgs
729-
FatalError("InitializeContextRuntime()",
730-
"invalid --disable-proto mode");
729+
OnFatalError("InitializeContextRuntime()", "invalid --disable-proto mode");
731730
}
732731

733732
return Just(true);
Collapse file

‎src/inspector_agent.cc‎

Copy file name to clipboardExpand all lines: src/inspector_agent.cc
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace node {
3636
namespace inspector {
3737
namespace {
3838

39-
using node::FatalError;
39+
using node::OnFatalError;
4040

4141
using v8::Context;
4242
using v8::Function;
@@ -901,8 +901,8 @@ void Agent::ToggleAsyncHook(Isolate* isolate, Local<Function> fn) {
901901
USE(fn->Call(context, Undefined(isolate), 0, nullptr));
902902
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
903903
PrintCaughtException(isolate, context, try_catch);
904-
FatalError("\nnode::inspector::Agent::ToggleAsyncHook",
905-
"Cannot toggle Inspector's AsyncHook, please report this.");
904+
OnFatalError("\nnode::inspector::Agent::ToggleAsyncHook",
905+
"Cannot toggle Inspector's AsyncHook, please report this.");
906906
}
907907
}
908908

Collapse file

‎src/node.h‎

Copy file name to clipboardExpand all lines: src/node.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);
722722
// a snapshot and have a main context that was read from that snapshot.
723723
NODE_EXTERN v8::Local<v8::Context> GetMainContext(Environment* env);
724724

725-
NODE_EXTERN void OnFatalError(const char* location, const char* message);
725+
[[noreturn]] NODE_EXTERN void OnFatalError(const char* location,
726+
const char* message);
726727
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
727728
NODE_EXTERN bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
728729
v8::Local<v8::String>);
Collapse file

‎src/node_api.cc‎

Copy file name to clipboardExpand all lines: src/node_api.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ NAPI_NO_RETURN void NAPI_CDECL napi_fatal_error(const char* location,
805805
message_string.assign(const_cast<char*>(message), strlen(message));
806806
}
807807

808-
node::FatalError(location_string.c_str(), message_string.c_str());
808+
node::OnFatalError(location_string.c_str(), message_string.c_str());
809809
}
810810

811811
napi_status NAPI_CDECL
Collapse file

‎src/node_errors.cc‎

Copy file name to clipboardExpand all lines: src/node_errors.cc
+3-8Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,7 @@ static void ReportFatalException(Environment* env,
504504
fflush(stderr);
505505
}
506506

507-
[[noreturn]] void FatalError(const char* location, const char* message) {
508-
OnFatalError(location, message);
509-
// to suppress compiler warning
510-
ABORT();
511-
}
512-
513-
void OnFatalError(const char* location, const char* message) {
507+
[[noreturn]] void OnFatalError(const char* location, const char* message) {
514508
if (location) {
515509
FPrintF(stderr, "FATAL ERROR: %s %s\n", location, message);
516510
} else {
@@ -532,7 +526,8 @@ void OnFatalError(const char* location, const char* message) {
532526
ABORT();
533527
}
534528

535-
void OOMErrorHandler(const char* location, const v8::OOMDetails& details) {
529+
[[noreturn]] void OOMErrorHandler(const char* location,
530+
const v8::OOMDetails& details) {
536531
const char* message =
537532
details.is_heap_oom ? "Allocation failed - JavaScript heap out of memory"
538533
: "Allocation failed - process out of memory";
Collapse file

‎src/node_errors.h‎

Copy file name to clipboardExpand all lines: src/node_errors.h
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ void AppendExceptionLine(Environment* env,
1919
v8::Local<v8::Message> message,
2020
enum ErrorHandlingMode mode);
2121

22-
[[noreturn]] void FatalError(const char* location, const char* message);
23-
void OnFatalError(const char* location, const char* message);
24-
void OOMErrorHandler(const char* location, const v8::OOMDetails& details);
22+
[[noreturn]] void OnFatalError(const char* location, const char* message);
23+
[[noreturn]] void OOMErrorHandler(const char* location,
24+
const v8::OOMDetails& details);
2525

2626
// Helpers to construct errors similar to the ones provided by
2727
// lib/internal/errors.js.
Collapse file

‎src/node_watchdog.cc‎

Copy file name to clipboardExpand all lines: src/node_watchdog.cc
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms, bool* timed_out)
4545
int rc;
4646
rc = uv_loop_init(&loop_);
4747
if (rc != 0) {
48-
FatalError("node::Watchdog::Watchdog()",
49-
"Failed to initialize uv loop.");
48+
OnFatalError("node::Watchdog::Watchdog()", "Failed to initialize uv loop.");
5049
}
5150

5251
rc = uv_async_init(&loop_, &async_, [](uv_async_t* signal) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.