diff --git a/doc/api/errors.md b/doc/api/errors.md index 338afb6bf520eb..a7aad1c746519e 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -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. - -### `ERR_CPU_USAGE` - -The native call from `process.cpuUsage` could not be processed. - ### `ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED` @@ -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. + +### `ERR_CPU_USAGE` + + +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 diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 4568980db920b3..2fbd5084a575d2 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -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); diff --git a/lib/internal/process/per_thread.js b/lib/internal/process/per_thread.js index 80bda3df9ace37..b061dd340c78cc 100644 --- a/lib/internal/process/per_thread.js +++ b/lib/internal/process/per_thread.js @@ -25,7 +25,6 @@ const { errnoException, codes: { ERR_ASSERTION, - ERR_CPU_USAGE, ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, ERR_OUT_OF_RANGE, @@ -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) { diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index d14a7642b42ab4..e708fe7f090385 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -95,15 +95,13 @@ static void Chdir(const FunctionCallbackInfo& args) { // Returns those values as Float64 microseconds in the elements of the array // passed to the function. static void CPUUsage(const FunctionCallbackInfo& 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 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());