From 0552c150ebe58c9599c23177bdc5ffad22303d5d Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Thu, 13 Aug 2020 23:11:44 +0530 Subject: [PATCH 1/2] src: error reporting on CPUUsage 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. --- doc/api/errors.md | 10 +++++----- lib/internal/errors.js | 1 - lib/internal/process/per_thread.js | 6 +----- src/node_process_methods.cc | 8 +++----- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/doc/api/errors.md b/doc/api/errors.md index 338afb6bf520eb..1b9df826891b65 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,11 @@ 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()); From 4a54765633d0b8955ace27c1648e42673d4b6250 Mon Sep 17 00:00:00 2001 From: Yash Ladha <201551061@iiitvadodara.ac.in> Date: Mon, 24 Aug 2020 09:48:21 +0530 Subject: [PATCH 2/2] Update doc/api/errors.md Co-authored-by: Anna Henningsen --- doc/api/errors.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/api/errors.md b/doc/api/errors.md index 1b9df826891b65..a7aad1c746519e 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -2722,6 +2722,9 @@ closed. ### `ERR_CPU_USAGE` + The native call from `process.cpuUsage` could not be processed.