Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix error reporting on CPUUsage #34762

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions doc/api/errors.md
Expand Up @@ -729,11 +729,6 @@ when an error occurs (and is caught) during the creation of the
context, for example, when the allocation fails or the maximum call stack
size is reached when the context is created.

<a id="ERR_CPU_USAGE"></a>
### `ERR_CPU_USAGE`

The native call from `process.cpuUsage` could not be processed.

<a id="ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED"></a>
### `ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED`

Expand Down Expand Up @@ -2725,6 +2720,14 @@ removed: v10.0.0
Used when an attempt is made to use a `zlib` object after it has already been
closed.

<a id="ERR_CPU_USAGE"></a>
### `ERR_CPU_USAGE`
yashLadha marked this conversation as resolved.
Show resolved Hide resolved
<!-- YAML
removed: REPLACEME
-->

The native call from `process.cpuUsage` could not be processed.

[ES Module]: esm.md
[ICU]: intl.md#intl_internationalization_support
[Node.js error codes]: #nodejs-error-codes
Expand Down
1 change: 0 additions & 1 deletion lib/internal/errors.js
Expand Up @@ -787,7 +787,6 @@ E('ERR_CHILD_PROCESS_STDIO_MAXBUFFER', '%s maxBuffer length exceeded',
E('ERR_CONSOLE_WRITABLE_STREAM',
'Console expects a writable stream instance for %s', TypeError);
E('ERR_CONTEXT_NOT_INITIALIZED', 'context used is not initialized', Error);
E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s', Error);
E('ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED',
'Custom engines not supported by this OpenSSL', Error);
E('ERR_CRYPTO_ECDH_INVALID_FORMAT', 'Invalid ECDH format: %s', TypeError);
Expand Down
6 changes: 1 addition & 5 deletions lib/internal/process/per_thread.js
Expand Up @@ -25,7 +25,6 @@ const {
errnoException,
codes: {
ERR_ASSERTION,
ERR_CPU_USAGE,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_OUT_OF_RANGE,
Expand Down Expand Up @@ -129,10 +128,7 @@ function wrapProcessMethods(binding) {
}

// Call the native function to get the current values.
const errmsg = _cpuUsage(cpuValues);
if (errmsg) {
throw new ERR_CPU_USAGE(errmsg);
}
_cpuUsage(cpuValues);

// If a previous value was passed in, return diff of current from previous.
if (prevValue) {
Expand Down
8 changes: 3 additions & 5 deletions src/node_process_methods.cc
Expand Up @@ -95,15 +95,13 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
// Returns those values as Float64 microseconds in the elements of the array
// passed to the function.
static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
uv_rusage_t rusage;

// Call libuv to get the values we'll return.
int err = uv_getrusage(&rusage);
if (err) {
// On error, return the strerror version of the error code.
Local<String> errmsg = OneByteString(args.GetIsolate(), uv_strerror(err));
return args.GetReturnValue().Set(errmsg);
}
if (err)
return env->ThrowUVException(err, "uv_getrusage");

// Get the double array pointer from the Float64Array argument.
CHECK(args[0]->IsFloat64Array());
Expand Down