From 1ffec6619ea500490a4bcb73a4dca99f17338491 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 81bbe15a9d2a42..b8948633cddfa4 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'); @@ -80,6 +80,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 046a6106ccd0e5..79a50692afc458 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); }