1
1
'use strict' ;
2
2
3
+ const errors = require ( 'internal/errors' ) ;
3
4
var _lazyConstants = null ;
4
5
5
6
function lazyConstants ( ) {
@@ -10,7 +11,7 @@ function lazyConstants() {
10
11
}
11
12
12
13
const assert = process . assert = function ( x , msg ) {
13
- if ( ! x ) throw new Error ( msg || 'assertion error' ) ;
14
+ if ( ! x ) throw new errors . Error ( 'ERR_ASSERTION' , msg || 'assertion error' ) ;
14
15
} ;
15
16
16
17
@@ -28,18 +29,20 @@ function setup_cpuUsage() {
28
29
// If a previous value was passed in, ensure it has the correct shape.
29
30
if ( prevValue ) {
30
31
if ( ! previousValueIsValid ( prevValue . user ) ) {
31
- throw new TypeError ( 'value of user property of argument is invalid' ) ;
32
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,
33
+ 'preValue.user' , 'Number' ) ;
32
34
}
33
35
34
36
if ( ! previousValueIsValid ( prevValue . system ) ) {
35
- throw new TypeError ( 'value of system property of argument is invalid' ) ;
37
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,
38
+ 'preValue.system' , 'Number' ) ;
36
39
}
37
40
}
38
41
39
42
// Call the native function to get the current values.
40
43
const errmsg = _cpuUsage ( cpuValues ) ;
41
44
if ( errmsg ) {
42
- throw new Error ( 'unable to obtain CPU usage: ' + errmsg ) ;
45
+ throw new errors . Error ( 'ERR_CPU_USAGE' , errmsg ) ;
43
46
}
44
47
45
48
// If a previous value was passed in, return diff of current from previous.
@@ -81,8 +84,8 @@ function setup_hrtime() {
81
84
const needsBorrow = nsec < 0 ;
82
85
return [ needsBorrow ? sec - 1 : sec , needsBorrow ? nsec + 1e9 : nsec ] ;
83
86
}
84
-
85
- throw new TypeError ( 'process.hrtime() only accepts an Array tuple ' ) ;
87
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' ,
88
+ 'process.hrtime()' , ' Array') ;
86
89
}
87
90
88
91
return [
@@ -132,8 +135,7 @@ function setupConfig(_source) {
132
135
des . value = require ( 'internal/util' ) . deprecate ( function v8BreakIterator ( ) {
133
136
if ( processConfig . hasSmallICU && ! processConfig . icuDataDir ) {
134
137
// Intl.v8BreakIterator() would crash w/ fatal error, so throw instead.
135
- throw new Error ( 'v8BreakIterator: full ICU data not installed. ' +
136
- 'See https://github.com/nodejs/node/wiki/Intl' ) ;
138
+ throw new errors . Error ( 'ERR_V8BREAKITERATOR' ) ;
137
139
}
138
140
return Reflect . construct ( oldV8BreakIterator , arguments ) ;
139
141
} , 'Intl.v8BreakIterator is deprecated and will be removed soon.' ,
@@ -161,7 +163,7 @@ function setupKillAndExit() {
161
163
162
164
// eslint-disable-next-line eqeqeq
163
165
if ( pid != ( pid | 0 ) ) {
164
- throw new TypeError ( 'invalid pid' ) ;
166
+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , ' pid' , 'Number ') ;
165
167
}
166
168
167
169
// preserve null signal
@@ -172,7 +174,7 @@ function setupKillAndExit() {
172
174
if ( lazyConstants ( ) [ sig ] ) {
173
175
err = process . _kill ( pid , lazyConstants ( ) [ sig ] ) ;
174
176
} else {
175
- throw new Error ( `Unknown signal: ${ sig } `) ;
177
+ throw new errors . Error ( 'ERR_UNKNOWN_SIGNAL' , ` ${ sig } `) ;
176
178
}
177
179
}
178
180
0 commit comments