src: consolidate exit codes in the code base

Add an ExitCode enum class and use it throughout the code base
instead of hard-coding the exit codes everywhere. At the moment,
the exit codes used in many places do not actually conform to
what the documentation describes. With the new enums (which
are also available to the JS land as constants in an internal
binding) we could migrate to a more consistent usage of the
codes, and eventually expose the constants to the user land
when they are stable enough.

PR-URL: https://github.com/nodejs/node/pull/44746
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Joyee Cheung authored and GitHub committed 2022-10-06 12:41:16 +00:00
1 parent 66cedb4600
commit be525d7d04
36 files changed
+381 -177

No files matched your search

+3 -2
View File
@@ -5,6 +5,7 @@
#include <optional>
#include <unordered_map>
#include "node_exit_code.h"
#include "node_messaging.h"
#include "uv.h"
@@ -41,7 +42,7 @@ class Worker : public AsyncWrap {
// Forcibly exit the thread with a specified exit code. This may be called
// from any thread. `error_code` and `error_message` can be used to create
// a custom `'error'` event before emitting `'exit'`.
void Exit(int code,
void Exit(ExitCode code,
const char* error_code = nullptr,
const char* error_message = nullptr);
@@ -95,7 +96,7 @@ class Worker : public AsyncWrap {
const char* custom_error_ = nullptr;
std::string custom_error_str_;
int exit_code_ = 0;
ExitCode exit_code_ = ExitCode::kNoFailure;
ThreadId thread_id_;
uintptr_t stack_base_ = 0;