Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2021-03-04 07:17:11 +0300
committerGus Caplan <me@gus.host>2021-03-09 19:12:53 +0300
commit853086fbaa9ca7c698c891fe32a3a42c985e743d (patch)
tree337891dd642b7785dbefa8c7bab1af32136f4d11 /src/node_errors.h
parent16151bec081b55d8b2bb936f1f00207120a770db (diff)
src: add error formatting support
PR-URL: https://github.com/nodejs/node/pull/37598 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'src/node_errors.h')
-rw-r--r--src/node_errors.h50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/node_errors.h b/src/node_errors.h
index 984603c42e2..1ae461f23d3 100644
--- a/src/node_errors.h
+++ b/src/node_errors.h
@@ -3,6 +3,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+#include "debug_utils-inl.h"
#include "env.h"
#include "v8.h"
@@ -75,29 +76,40 @@ void OnFatalError(const char* location, const char* message);
V(ERR_TLS_INVALID_PROTOCOL_METHOD, TypeError) \
V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, Error) \
V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \
+ V(ERR_VM_MODULE_LINK_FAILURE, Error) \
V(ERR_WASI_NOT_STARTED, Error) \
V(ERR_WORKER_INIT_FAILED, Error) \
- V(ERR_PROTO_ACCESS, Error) \
+ V(ERR_PROTO_ACCESS, Error)
-#define V(code, type) \
- inline v8::Local<v8::Value> code(v8::Isolate* isolate, \
- const char* message) { \
- v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
- v8::Local<v8::String> js_msg = OneByteString(isolate, message); \
- v8::Local<v8::Object> e = \
- v8::Exception::type(js_msg)->ToObject( \
- isolate->GetCurrentContext()).ToLocalChecked(); \
- e->Set(isolate->GetCurrentContext(), OneByteString(isolate, "code"), \
- js_code).Check(); \
- return e; \
- } \
- inline void THROW_ ## code(v8::Isolate* isolate, const char* message) { \
- isolate->ThrowException(code(isolate, message)); \
- } \
- inline void THROW_ ## code(Environment* env, const char* message) { \
- THROW_ ## code(env->isolate(), message); \
+#define V(code, type) \
+ template <typename... Args> \
+ inline v8::Local<v8::Value> code( \
+ v8::Isolate* isolate, const char* format, Args&&... args) { \
+ std::string message = SPrintF(format, std::forward<Args>(args)...); \
+ v8::Local<v8::String> js_code = OneByteString(isolate, #code); \
+ v8::Local<v8::String> js_msg = \
+ OneByteString(isolate, message.c_str(), message.length()); \
+ v8::Local<v8::Object> e = v8::Exception::type(js_msg) \
+ ->ToObject(isolate->GetCurrentContext()) \
+ .ToLocalChecked(); \
+ e->Set(isolate->GetCurrentContext(), \
+ OneByteString(isolate, "code"), \
+ js_code) \
+ .Check(); \
+ return e; \
+ } \
+ template <typename... Args> \
+ inline void THROW_##code( \
+ v8::Isolate* isolate, const char* format, Args&&... args) { \
+ isolate->ThrowException( \
+ code(isolate, format, std::forward<Args>(args)...)); \
+ } \
+ template <typename... Args> \
+ inline void THROW_##code( \
+ Environment* env, const char* format, Args&&... args) { \
+ THROW_##code(env->isolate(), format, std::forward<Args>(args)...); \
}
- ERRORS_WITH_CODE(V)
+ERRORS_WITH_CODE(V)
#undef V
// Errors with predefined static messages