11'use strict' ;
22
3+ const errors = require ( 'internal/errors' ) ;
34var _lazyConstants = null ;
45
56function lazyConstants ( ) {
@@ -10,7 +11,7 @@ function lazyConstants() {
1011}
1112
1213const 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' ) ;
1415} ;
1516
1617
@@ -28,18 +29,20 @@ function setup_cpuUsage() {
2829 // If a previous value was passed in, ensure it has the correct shape.
2930 if ( prevValue ) {
3031 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' ) ;
3234 }
3335
3436 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' ) ;
3639 }
3740 }
3841
3942 // Call the native function to get the current values.
4043 const errmsg = _cpuUsage ( cpuValues ) ;
4144 if ( errmsg ) {
42- throw new Error ( 'unable to obtain CPU usage: ' + errmsg ) ;
45+ throw new errors . Error ( 'ERR_CPU_USAGE' , errmsg ) ;
4346 }
4447
4548 // If a previous value was passed in, return diff of current from previous.
@@ -81,8 +84,8 @@ function setup_hrtime() {
8184 const needsBorrow = nsec < 0 ;
8285 return [ needsBorrow ? sec - 1 : sec , needsBorrow ? nsec + 1e9 : nsec ] ;
8386 }
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') ;
8689 }
8790
8891 return [
@@ -132,8 +135,7 @@ function setupConfig(_source) {
132135 des . value = require ( 'internal/util' ) . deprecate ( function v8BreakIterator ( ) {
133136 if ( processConfig . hasSmallICU && ! processConfig . icuDataDir ) {
134137 // 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' ) ;
137139 }
138140 return Reflect . construct ( oldV8BreakIterator , arguments ) ;
139141 } , 'Intl.v8BreakIterator is deprecated and will be removed soon.' ,
@@ -161,7 +163,7 @@ function setupKillAndExit() {
161163
162164 // eslint-disable-next-line eqeqeq
163165 if ( pid != ( pid | 0 ) ) {
164- throw new TypeError ( 'invalid pid' ) ;
166+ throw new errors . TypeError ( 'ERR_INVALID_ARG_TYPE' , ' pid' , 'Number ') ;
165167 }
166168
167169 // preserve null signal
@@ -172,7 +174,7 @@ function setupKillAndExit() {
172174 if ( lazyConstants ( ) [ sig ] ) {
173175 err = process . _kill ( pid , lazyConstants ( ) [ sig ] ) ;
174176 } else {
175- throw new Error ( `Unknown signal: ${ sig } `) ;
177+ throw new errors . Error ( 'ERR_UNKNOWN_SIGNAL' , ` ${ sig } `) ;
176178 }
177179 }
178180
0 commit comments