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:
authorbcoe <bencoe@google.com>2020-05-25 02:00:46 +0300
committerBenjamin Coe <bencoe@google.com>2020-05-25 08:03:34 +0300
commit458677f5ef2bd35da920246bb266502ea76bb66c (patch)
treee1809f38c6bbbf898287513a062ad588ba32e43d /src/node_errors.cc
parent8f10bb2da5bcf166fa1b414055f03352bbdb8126 (diff)
errors: print original exception context
When --enable-source-maps is set, the error context displayed above the stack trace now shows original source rather than transpiled. PR-URL: https://github.com/nodejs/node/pull/33491 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/node_errors.cc')
-rw-r--r--src/node_errors.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node_errors.cc b/src/node_errors.cc
index 4e13c24e15e..22bc4d994b8 100644
--- a/src/node_errors.cc
+++ b/src/node_errors.cc
@@ -57,6 +57,16 @@ static std::string GetErrorSource(Isolate* isolate,
node::Utf8Value encoded_source(isolate, source_line_maybe.ToLocalChecked());
std::string sourceline(*encoded_source, encoded_source.length());
+ // If source maps have been enabled, the exception line will instead be
+ // added in the JavaScript context:
+ Environment* env = Environment::GetCurrent(isolate);
+ const bool has_source_map_url =
+ !message->GetScriptOrigin().SourceMapUrl().IsEmpty();
+ if (has_source_map_url && env->source_maps_enabled()) {
+ *added_exception_line = false;
+ return sourceline;
+ }
+
if (sourceline.find("node-do-not-add-exception-line") != std::string::npos) {
*added_exception_line = false;
return sourceline;
@@ -802,6 +812,11 @@ void SetPrepareStackTraceCallback(const FunctionCallbackInfo<Value>& args) {
env->set_prepare_stack_trace_callback(args[0].As<Function>());
}
+static void EnableSourceMaps(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+ env->set_source_maps_enabled(true);
+}
+
static void SetEnhanceStackForFatalException(
const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
@@ -840,6 +855,7 @@ void Initialize(Local<Object> target,
Environment* env = Environment::GetCurrent(context);
env->SetMethod(
target, "setPrepareStackTraceCallback", SetPrepareStackTraceCallback);
+ env->SetMethod(target, "enableSourceMaps", EnableSourceMaps);
env->SetMethod(target,
"setEnhanceStackForFatalException",
SetEnhanceStackForFatalException);