From dcc1cf4f4ebb0cb8dad0ffc1921cff152a8f01ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Wed, 24 Aug 2022 17:21:42 -0500 Subject: [PATCH] src: add error handling to `uv_uptime` call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/44386 Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- lib/os.js | 4 +++- src/node_os.cc | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/os.js b/lib/os.js index c3bb404b2d776b..860348a472f325 100644 --- a/lib/os.js +++ b/lib/os.js @@ -55,7 +55,7 @@ const { getOSInformation: _getOSInformation, getTotalMem, getUserInfo, - getUptime, + getUptime: _getUptime, isBigEndian, setPriority: _setPriority } = internalBinding('os'); @@ -81,6 +81,8 @@ const { const getHomeDirectory = getCheckedFunction(_getHomeDirectory); const getHostname = getCheckedFunction(_getHostname); const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses); +const getUptime = getCheckedFunction(_getUptime); + /** * @returns {string} */ diff --git a/src/node_os.cc b/src/node_os.cc index 9079faf887dc7a..4a3b9f608d702f 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -149,10 +149,15 @@ static void GetTotalMemory(const FunctionCallbackInfo& args) { static void GetUptime(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); double uptime; int err = uv_uptime(&uptime); - if (err == 0) - args.GetReturnValue().Set(uptime); + if (err != 0) { + env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_uptime"); + return args.GetReturnValue().SetUndefined(); + } + + args.GetReturnValue().Set(uptime); }