Skip to content

Commit

Permalink
src: error reporting on CPUUsage
Browse files Browse the repository at this point in the history
Currently we are returning the stringified error code while in other
process methods we are throwin a UVException and only exclusion is in
the CPUUsage. Converted it to follow the convention.

PR-URL: #34762
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Mary Marchini <oss@mmarchini.me>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
yashLadha authored and aduh95 committed Oct 16, 2020
1 parent 9e5a27a commit eeb6b47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
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`
<!-- 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

0 comments on commit eeb6b47

Please sign in to comment.