| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7024c5a commit 062071a
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -114,6 +114,7 @@ E('ERR_ARG_NOT_ITERABLE', '%s must be iterable'); | |||
| 114 | 114 | E('ERR_ASSERTION', (msg) => msg); | |
| 115 | 115 | E('ERR_CONSOLE_WRITABLE_STREAM', | |
| 116 | 116 | (name) => `Console expects a writable stream instance for ${name}`); | |
| 117 | + E('ERR_CPU_USAGE', (errMsg) => `Unable to obtain cpu usage ${errMsg}`); | ||
| 117 | 118 | E('ERR_HTTP_HEADERS_SENT', | |
| 118 | 119 | 'Cannot render headers after they are sent to the client'); | |
| 119 | 120 | E('ERR_HTTP_INVALID_CHAR', 'Invalid character in statusMessage.'); | |
@@ -160,6 +161,8 @@ E('ERR_SOCKET_BAD_TYPE', | |||
| 160 | 161 | E('ERR_SOCKET_CANNOT_SEND', 'Unable to send data'); | |
| 161 | 162 | E('ERR_SOCKET_BAD_PORT', 'Port should be > 0 and < 65536'); | |
| 162 | 163 | E('ERR_SOCKET_DGRAM_NOT_RUNNING', 'Not running'); | |
| 164 | + E('ERR_V8BREAKITERATOR', 'full ICU data not installed. ' + | ||
| 165 | + 'See https://github.com/nodejs/node/wiki/Intl'); | ||
| 163 | 166 | // Add new errors from here... | |
| 164 | 167 | ||
| 165 | 168 | function invalidArgType(name, expected, actual) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,21 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | ||
| 5 | 5 | assert.strictEqual(process.assert(1, 'error'), undefined); | |
| 6 | 6 | assert.throws(() => { | |
| 7 | 7 | process.assert(undefined, 'errorMessage'); | |
| 8 | - }, /^Error: errorMessage$/); | ||
| 8 | + }, common.expectsError({ | ||
| 9 | + code: 'ERR_ASSERTION', | ||
| 10 | + type: Error, | ||
| 11 | + message: 'errorMessage' | ||
| 12 | + }) | ||
| 13 | + ); | ||
| 9 | 14 | assert.throws(() => { | |
| 10 | 15 | process.assert(false); | |
| 11 | - }, /^Error: assertion error$/); | ||
| 16 | + }, common.expectsError({ | ||
| 17 | + code: 'ERR_ASSERTION', | ||
| 18 | + type: Error, | ||
| 19 | + message: 'assertion error' | ||
| 20 | + }) | ||
| 21 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 3 | 2 | const assert = require('assert'); | |
| 4 | - | ||
| 3 | + const common = require('../common'); | ||
| 5 | 4 | const result = process.cpuUsage(); | |
| 6 | 5 | ||
| 7 | 6 | // Validate the result of calling with no previous value argument. | |
@@ -32,11 +31,18 @@ for (let i = 0; i < 10; i++) { | |||
| 32 | 31 | assert(diffUsage.user >= 0); | |
| 33 | 32 | assert(diffUsage.system >= 0); | |
| 34 | 33 | } | |
| 34 | + const invalidUserArgument = common.expectsError({ | ||
| 35 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 36 | + type: TypeError, | ||
| 37 | + message: 'The "preValue.user" argument must be of type Number' | ||
| 38 | + }); | ||
| 39 | + | ||
| 40 | + const invalidSystemArgument = common.expectsError({ | ||
| 41 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 42 | + type: TypeError, | ||
| 43 | + message: 'The "preValue.system" argument must be of type Number' | ||
| 44 | + }); | ||
| 35 | 45 | ||
| 36 | - const invalidUserArgument = | ||
| 37 | - /^TypeError: value of user property of argument is invalid$/; | ||
| 38 | - const invalidSystemArgument = | ||
| 39 | - /^TypeError: value of system property of argument is invalid$/; | ||
| 40 | 46 | ||
| 41 | 47 | // Ensure that an invalid shape for the previous value argument throws an error. | |
| 42 | 48 | assert.throws(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | ||
| 26 | 26 | // the default behavior, return an Array "tuple" of numbers | |
@@ -32,19 +32,25 @@ validateTuple(tuple); | |||
| 32 | 32 | // validate that passing an existing tuple returns another valid tuple | |
| 33 | 33 | validateTuple(process.hrtime(tuple)); | |
| 34 | 34 | ||
| 35 | + const invalidHrtimeArgument = common.expectsError({ | ||
| 36 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 37 | + type: TypeError, | ||
| 38 | + message: 'The "process.hrtime()" argument must be of type Array' | ||
| 39 | + }); | ||
| 40 | + | ||
| 35 | 41 | // test that only an Array may be passed to process.hrtime() | |
| 36 | 42 | assert.throws(() => { | |
| 37 | 43 | process.hrtime(1); | |
| 38 | - }, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/); | ||
| 44 | + }, invalidHrtimeArgument); | ||
| 39 | 45 | assert.throws(() => { | |
| 40 | 46 | process.hrtime([]); | |
| 41 | - }, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/); | ||
| 47 | + }, invalidHrtimeArgument); | ||
| 42 | 48 | assert.throws(() => { | |
| 43 | 49 | process.hrtime([1]); | |
| 44 | - }, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/); | ||
| 50 | + }, invalidHrtimeArgument); | ||
| 45 | 51 | assert.throws(() => { | |
| 46 | 52 | process.hrtime([1, 2, 3]); | |
| 47 | - }, /^TypeError: process\.hrtime\(\) only accepts an Array tuple$/); | ||
| 53 | + }, invalidHrtimeArgument); | ||
| 48 | 54 | ||
| 49 | 55 | function validateTuple(tuple) { | |
| 50 | 56 | assert(Array.isArray(tuple)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | // USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | - require('../common'); | ||
| 23 | + const common = require('../common'); | ||
| 24 | 24 | const assert = require('assert'); | |
| 25 | 25 | ||
| 26 | 26 | // test variants of pid | |
@@ -38,20 +38,35 @@ const assert = require('assert'); | |||
| 38 | 38 | // | |
| 39 | 39 | // process.pid, String(process.pid): ourself | |
| 40 | 40 | ||
| 41 | + const invalidPidArgument = common.expectsError({ | ||
| 42 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 43 | + type: TypeError, | ||
| 44 | + message: 'The "pid" argument must be of type Number' | ||
| 45 | + }); | ||
| 46 | + | ||
| 41 | 47 | assert.throws(function() { process.kill('SIGTERM'); }, | |
| 42 | - /^TypeError: invalid pid$/); | ||
| 43 | - assert.throws(function() { process.kill(null); }, /^TypeError: invalid pid$/); | ||
| 48 | + invalidPidArgument); | ||
| 49 | + assert.throws(function() { process.kill(null); }, | ||
| 50 | + invalidPidArgument); | ||
| 44 | 51 | assert.throws(function() { process.kill(undefined); }, | |
| 45 | - /^TypeError: invalid pid$/); | ||
| 52 | + invalidPidArgument); | ||
| 46 | 53 | assert.throws(function() { process.kill(+'not a number'); }, | |
| 47 | - /^TypeError: invalid pid$/); | ||
| 48 | - assert.throws(function() { process.kill(1 / 0); }, /^TypeError: invalid pid$/); | ||
| 49 | - assert.throws(function() { process.kill(-1 / 0); }, /^TypeError: invalid pid$/); | ||
| 54 | + invalidPidArgument); | ||
| 55 | + assert.throws(function() { process.kill(1 / 0); }, | ||
| 56 | + invalidPidArgument); | ||
| 57 | + assert.throws(function() { process.kill(-1 / 0); }, | ||
| 58 | + invalidPidArgument); | ||
| 50 | 59 | ||
| 51 | 60 | // Test that kill throws an error for invalid signal | |
| 61 | + const unknownSignal = common.expectsError({ | ||
| 62 | + code: 'ERR_UNKNOWN_SIGNAL', | ||
| 63 | + type: Error, | ||
| 64 | + message: 'Unknown signal: test' | ||
| 65 | + }); | ||
| 66 | + | ||
| 52 | 67 | ||
| 53 | 68 | assert.throws(function() { process.kill(1, 'test'); }, | |
| 54 | - /^Error: Unknown signal: test$/); | ||
| 69 | + unknownSignal); | ||
| 55 | 70 | ||
| 56 | 71 | // Test kill argument processing in valid cases. | |
| 57 | 72 | // | |
| Back | FazBrowse Home | New Git URL |
0 commit comments