Skip to content

Commit 8f3ed25

Browse files
committed
src: add error handling to uv_uptime call
PR-URL: #44386 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent f38987e commit 8f3ed25

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');
@@ -80,6 +80,8 @@ const {
8080
const getHomeDirectory = getCheckedFunction(_getHomeDirectory);
8181
const getHostname = getCheckedFunction(_getHostname);
8282
const getInterfaceAddresses = getCheckedFunction(_getInterfaceAddresses);
83+
const getUptime = getCheckedFunction(_getUptime);
84+
8385
/**
8486
* @returns {string}
8587
*/

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)