mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
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>
This commit is contained in:
1 parent
8f10bb2da5
commit
458677f5ef
18 files changed
+270
-21
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user