Skip to content

Commit

Permalink
src: add error handling to uv_uptime call
Browse files Browse the repository at this point in the history
PR-URL: #44386
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
juanarbol authored and RafaelGSS committed Sep 7, 2022
1 parent e36ed44 commit dcc1cf4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const {
getOSInformation: _getOSInformation,
getTotalMem,
getUserInfo,
getUptime,
getUptime: _getUptime,
isBigEndian,
setPriority: _setPriority
} = internalBinding('os');
Expand All @@ -81,6 +81,8 @@ const {
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
const getHostname = getCheckedFunction(_getHostname);
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
const getUptime = getCheckedFunction(_getUptime);

/**
* @returns {string}
*/
Expand Down
9 changes: 7 additions & 2 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@ static void GetTotalMemory(const FunctionCallbackInfo<Value>& args) {


static void GetUptime(const FunctionCallbackInfo<Value>& 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);
}


Expand Down

0 comments on commit dcc1cf4

Please sign in to comment.