From 9d7adf22af8238bc06a2fac3631117bbeb233ece Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 16 Jul 2025 12:19:51 -0700 Subject: [PATCH] fix: deprecation warning crash when no Node.js environment available (#47770) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- shell/common/node_util.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/shell/common/node_util.cc b/shell/common/node_util.cc index 7f6ffa93ea63..ba0d4437b87e 100644 --- a/shell/common/node_util.cc +++ b/shell/common/node_util.cc @@ -65,8 +65,13 @@ void EmitWarning(const std::string_view warning_msg, void EmitWarning(v8::Isolate* isolate, const std::string_view warning_msg, const std::string_view warning_type) { - node::ProcessEmitWarningGeneric(node::Environment::GetCurrent(isolate), - warning_msg, warning_type); + node::Environment* env = node::Environment::GetCurrent(isolate); + if (!env) { + // No Node.js environment available, fall back to console logging. + LOG(WARNING) << "[" << warning_type << "] " << warning_msg; + return; + } + node::ProcessEmitWarningGeneric(env, warning_msg, warning_type); } void EmitDeprecationWarning(const std::string_view warning_msg, @@ -78,8 +83,14 @@ void EmitDeprecationWarning(const std::string_view warning_msg, void EmitDeprecationWarning(v8::Isolate* isolate, const std::string_view warning_msg, const std::string_view deprecation_code) { - node::ProcessEmitWarningGeneric(node::Environment::GetCurrent(isolate), - warning_msg, "DeprecationWarning", + node::Environment* env = node::Environment::GetCurrent(isolate); + if (!env) { + // No Node.js environment available, fall back to console logging. + LOG(WARNING) << "[DeprecationWarning] " << warning_msg + << " (code: " << deprecation_code << ")"; + return; + } + node::ProcessEmitWarningGeneric(env, warning_msg, "DeprecationWarning", deprecation_code); }