Skip to content

Commit dcc1cf4

Browse files
juanarbolRafaelGSS
authored andcommitted
src: add error handling to uv_uptime call
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>
1 parent e36ed44 commit dcc1cf4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/os.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const {
5555
getOSInformation: _getOSInformation,
5656
getTotalMem,
5757
getUserInfo,
58-
getUptime,
58+
getUptime: _getUptime,
5959
isBigEndian,
6060
setPriority: _setPriority
6161
} = internalBinding('os');
@@ -81,6 +81,8 @@ const {
8181
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
8282
const getHostname = getCheckedFunction(_getHostname);
8383
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
84+
const getUptime = getCheckedFunction(_getUptime);
85+
8486
/**
8587
* @returns {string}
8688
*/

src/node_os.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,15 @@ static void GetTotalMemory(const FunctionCallbackInfo<Value>& args) {
149149

150150

151151
static void GetUptime(const FunctionCallbackInfo<Value>& args) {
152+
Environment* env = Environment::GetCurrent(args);
152153
double uptime;
153154
int err = uv_uptime(&uptime);
154-
if (err == 0)
155-
args.GetReturnValue().Set(uptime);
155+
if (err != 0) {
156+
env->CollectUVExceptionInfo(args[args.Length() - 1], err, "uv_uptime");
157+
return args.GetReturnValue().SetUndefined();
158+
}
159+
160+
args.GetReturnValue().Set(uptime);
156161
}
157162

158163

0 commit comments

Comments
 (0)