Skip to content

Commit eeb6b47

Browse files
yashLadhaaduh95
authored andcommittedOct 16, 2020
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. 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>
1 parent 9e5a27a commit eeb6b47

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed
 

‎doc/api/errors.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -729,11 +729,6 @@ when an error occurs (and is caught) during the creation of the
729729
context, for example, when the allocation fails or the maximum call stack
730730
size is reached when the context is created.
731731

732-
<a id="ERR_CPU_USAGE"></a>
733-
### `ERR_CPU_USAGE`
734-
735-
The native call from `process.cpuUsage` could not be processed.
736-
737732
<a id="ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED"></a>
738733
### `ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED`
739734

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

2723+
<a id="ERR_CPU_USAGE"></a>
2724+
### `ERR_CPU_USAGE`
2725+
<!-- YAML
2726+
removed: REPLACEME
2727+
-->
2728+
2729+
The native call from `process.cpuUsage` could not be processed.
2730+
27282731
[ES Module]: esm.md
27292732
[ICU]: intl.md#intl_internationalization_support
27302733
[Node.js error codes]: #nodejs-error-codes

‎lib/internal/errors.js

-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,6 @@ E('ERR_CHILD_PROCESS_STDIO_MAXBUFFER', '%s maxBuffer length exceeded',
787787
E('ERR_CONSOLE_WRITABLE_STREAM',
788788
'Console expects a writable stream instance for %s', TypeError);
789789
E('ERR_CONTEXT_NOT_INITIALIZED', 'context used is not initialized', Error);
790-
E('ERR_CPU_USAGE', 'Unable to obtain cpu usage %s', Error);
791790
E('ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED',
792791
'Custom engines not supported by this OpenSSL', Error);
793792
E('ERR_CRYPTO_ECDH_INVALID_FORMAT', 'Invalid ECDH format: %s', TypeError);

‎lib/internal/process/per_thread.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const {
2525
errnoException,
2626
codes: {
2727
ERR_ASSERTION,
28-
ERR_CPU_USAGE,
2928
ERR_INVALID_ARG_TYPE,
3029
ERR_INVALID_ARG_VALUE,
3130
ERR_OUT_OF_RANGE,
@@ -129,10 +128,7 @@ function wrapProcessMethods(binding) {
129128
}
130129

131130
// Call the native function to get the current values.
132-
const errmsg = _cpuUsage(cpuValues);
133-
if (errmsg) {
134-
throw new ERR_CPU_USAGE(errmsg);
135-
}
131+
_cpuUsage(cpuValues);
136132

137133
// If a previous value was passed in, return diff of current from previous.
138134
if (prevValue) {

‎src/node_process_methods.cc

+3-5
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ static void Chdir(const FunctionCallbackInfo<Value>& args) {
9595
// Returns those values as Float64 microseconds in the elements of the array
9696
// passed to the function.
9797
static void CPUUsage(const FunctionCallbackInfo<Value>& args) {
98+
Environment* env = Environment::GetCurrent(args);
9899
uv_rusage_t rusage;
99100

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.