From fed038172bc268c9a369a872a56f4f3e11dd6f3c Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Thu, 7 Nov 2024 10:35:27 -0300 Subject: [PATCH] fixup! fixup! src: add cli option to preserve env vars on dr --- lib/internal/process/report.js | 11 +++++------ src/node_report_module.cc | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index 9ad8ec18f21645..58104bd1095aa1 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.js @@ -16,8 +16,6 @@ const { } = require('internal/validators'); const nr = internalBinding('report'); -let excludeEnv; - const report = { writeReport(file, err) { if (typeof file === 'object' && file !== null) { @@ -108,10 +106,11 @@ const report = { nr.setReportOnUncaughtException(trigger); }, get excludeEnv() { - if (excludeEnv === undefined) { - excludeEnv = nr.shouldExcludeEnvironmentVariables(); - } - return excludeEnv; + return nr.getExcludeEnv(); + }, + set excludeEnv(b) { + validateBoolean(b, 'excludeEnv'); + nr.setExcludeEnv(b); }, }; diff --git a/src/node_report_module.cc b/src/node_report_module.cc index edddc0f584fd8a..7a87a53203dcc7 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -95,6 +95,17 @@ static void SetExcludeNetwork(const FunctionCallbackInfo& info) { env->options()->report_exclude_network = info[0]->IsTrue(); } +static void GetExcludeEnv(const FunctionCallbackInfo& info) { + Environment* env = Environment::GetCurrent(info); + info.GetReturnValue().Set(env->report_exclude_env()); +} + +static void SetExcludeEnv(const FunctionCallbackInfo& info) { + Environment* env = Environment::GetCurrent(info); + CHECK(info[0]->IsBoolean()); + env->options()->report_exclude_env = info[0]->IsTrue(); +} + static void GetDirectory(const FunctionCallbackInfo& info) { Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(info); @@ -170,12 +181,6 @@ static void ShouldReportOnUncaughtException( env->isolate_data()->options()->report_uncaught_exception); } -static void ShouldExcludeEnvironmentVariables( - const FunctionCallbackInfo& info) { - Environment* env = Environment::GetCurrent(info); - info.GetReturnValue().Set(env->report_exclude_env()); -} - static void SetReportOnUncaughtException( const FunctionCallbackInfo& info) { Environment* env = Environment::GetCurrent(info); @@ -193,6 +198,8 @@ static void Initialize(Local exports, SetMethod(context, exports, "setCompact", SetCompact); SetMethod(context, exports, "getExcludeNetwork", GetExcludeNetwork); SetMethod(context, exports, "setExcludeNetwork", SetExcludeNetwork); + SetMethod(context, exports, "getExcludeEnv", GetExcludeEnv); + SetMethod(context, exports, "setExcludeEnv", SetExcludeEnv); SetMethod(context, exports, "getDirectory", GetDirectory); SetMethod(context, exports, "setDirectory", SetDirectory); SetMethod(context, exports, "getFilename", GetFilename); @@ -208,10 +215,6 @@ static void Initialize(Local exports, exports, "shouldReportOnUncaughtException", ShouldReportOnUncaughtException); - SetMethod(context, - exports, - "shouldExcludeEnvironmentVariables", - ShouldExcludeEnvironmentVariables); SetMethod(context, exports, "setReportOnUncaughtException", @@ -225,6 +228,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(SetCompact); registry->Register(GetExcludeNetwork); registry->Register(SetExcludeNetwork); + registry->Register(GetExcludeEnv); + registry->Register(SetExcludeEnv); registry->Register(GetDirectory); registry->Register(SetDirectory); registry->Register(GetFilename); @@ -236,7 +241,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(ShouldReportOnSignal); registry->Register(SetReportOnSignal); registry->Register(ShouldReportOnUncaughtException); - registry->Register(ShouldExcludeEnvironmentVariables); registry->Register(SetReportOnUncaughtException); }