| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent a517466 commit 219932a
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1136,6 +1136,11 @@ Used when an attempt is made to launch a Node.js process with an unknown | |||
| 1136 | 1136 | by errors in user code, although it is not impossible. Occurrences of this error | |
| 1137 | 1137 | are most likely an indication of a bug within Node.js itself. | |
| 1138 | 1138 | ||
| 1139 | + <a id="ERR_VALUE_OUT_OF_RANGE"></a> | ||
| 1140 | + ### ERR_VALUE_OUT_OF_RANGE | ||
| 1141 | + | ||
| 1142 | + Used when a number value is out of range. | ||
| 1143 | + | ||
| 1139 | 1144 | <a id="ERR_V8BREAKITERATOR"></a> | |
| 1140 | 1145 | ### ERR_V8BREAKITERATOR | |
| 1141 | 1146 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ const { isUint8Array, createPromise, promiseResolve } = process.binding('util'); | |||
| 33 | 33 | const binding = process.binding('fs'); | |
| 34 | 34 | const fs = exports; | |
| 35 | 35 | const Buffer = require('buffer').Buffer; | |
| 36 | + const errors = require('internal/errors'); | ||
| 36 | 37 | const Stream = require('stream').Stream; | |
| 37 | 38 | const EventEmitter = require('events'); | |
| 38 | 39 | const FSReqWrap = binding.FSReqWrap; | |
@@ -72,8 +73,10 @@ function getOptions(options, defaultOptions) { | |||
| 72 | 73 | defaultOptions.encoding = options; | |
| 73 | 74 | options = defaultOptions; | |
| 74 | 75 | } else if (typeof options !== 'object') { | |
| 75 | - throw new TypeError('"options" must be a string or an object, got ' + | ||
| 76 | - typeof options + ' instead.'); | ||
| 76 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 77 | + 'options', | ||
| 78 | + ['string', 'object'], | ||
| 79 | + options); | ||
| 77 | 80 | } | |
| 78 | 81 | ||
| 79 | 82 | if (options.encoding !== 'buffer') | |
@@ -128,7 +131,7 @@ function makeCallback(cb) { | |||
| 128 | 131 | } | |
| 129 | 132 | ||
| 130 | 133 | if (typeof cb !== 'function') { | |
| 131 | - throw new TypeError('"callback" argument must be a function'); | ||
| 134 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 132 | 135 | } | |
| 133 | 136 | ||
| 134 | 137 | return function() { | |
@@ -145,7 +148,7 @@ function makeStatsCallback(cb) { | |||
| 145 | 148 | } | |
| 146 | 149 | ||
| 147 | 150 | if (typeof cb !== 'function') { | |
| 148 | - throw new TypeError('"callback" argument must be a function'); | ||
| 151 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 149 | 152 | } | |
| 150 | 153 | ||
| 151 | 154 | return function(err) { | |
@@ -156,8 +159,11 @@ function makeStatsCallback(cb) { | |||
| 156 | 159 | ||
| 157 | 160 | function nullCheck(path, callback) { | |
| 158 | 161 | if (('' + path).indexOf('\u0000') !== -1) { | |
| 159 | - var er = new Error('Path must be a string without null bytes'); | ||
| 160 | - er.code = 'ENOENT'; | ||
| 162 | + const er = new errors.Error('ERR_INVALID_ARG_TYPE', | ||
| 163 | + 'path', | ||
| 164 | + 'string without null bytes', | ||
| 165 | + path); | ||
| 166 | + | ||
| 161 | 167 | if (typeof callback !== 'function') | |
| 162 | 168 | throw er; | |
| 163 | 169 | process.nextTick(callback, er); | |
@@ -274,7 +280,7 @@ fs.access = function(path, mode, callback) { | |||
| 274 | 280 | callback = mode; | |
| 275 | 281 | mode = fs.F_OK; | |
| 276 | 282 | } else if (typeof callback !== 'function') { | |
| 277 | - throw new TypeError('"callback" argument must be a function'); | ||
| 283 | + throw new errors.TypeError('ERR_INVALID_CALLBACK'); | ||
| 278 | 284 | } | |
| 279 | 285 | ||
| 280 | 286 | if (handleError((path = getPathFromURL(path)), callback)) | |
@@ -1193,7 +1199,10 @@ function toUnixTimestamp(time) { | |||
| 1193 | 1199 | // convert to 123.456 UNIX timestamp | |
| 1194 | 1200 | return time.getTime() / 1000; | |
| 1195 | 1201 | } | |
| 1196 | - throw new Error('Cannot parse time: ' + time); | ||
| 1202 | + throw new errors.Error('ERR_INVALID_ARG_TYPE', | ||
| 1203 | + 'time', | ||
| 1204 | + ['Date', 'time in seconds'], | ||
| 1205 | + time); | ||
| 1197 | 1206 | } | |
| 1198 | 1207 | ||
| 1199 | 1208 | // exported for unit tests, not for public consumption | |
@@ -1495,7 +1504,10 @@ fs.watchFile = function(filename, options, listener) { | |||
| 1495 | 1504 | } | |
| 1496 | 1505 | ||
| 1497 | 1506 | if (typeof listener !== 'function') { | |
| 1498 | - throw new Error('"watchFile()" requires a listener function'); | ||
| 1507 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 1508 | + 'listener', | ||
| 1509 | + 'function', | ||
| 1510 | + listener); | ||
| 1499 | 1511 | } | |
| 1500 | 1512 | ||
| 1501 | 1513 | stat = statWatchers.get(filename); | |
@@ -1842,8 +1854,12 @@ fs.realpath = function realpath(p, options, callback) { | |||
| 1842 | 1854 | fs.mkdtemp = function(prefix, options, callback) { | |
| 1843 | 1855 | callback = makeCallback(typeof options === 'function' ? options : callback); | |
| 1844 | 1856 | options = getOptions(options, {}); | |
| 1845 | - if (!prefix || typeof prefix !== 'string') | ||
| 1846 | - throw new TypeError('filename prefix is required'); | ||
| 1857 | + if (!prefix || typeof prefix !== 'string') { | ||
| 1858 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 1859 | + 'prefix', | ||
| 1860 | + 'string', | ||
| 1861 | + prefix); | ||
| 1862 | + } | ||
| 1847 | 1863 | if (!nullCheck(prefix, callback)) { | |
| 1848 | 1864 | return; | |
| 1849 | 1865 | } | |
@@ -1856,8 +1872,12 @@ fs.mkdtemp = function(prefix, options, callback) { | |||
| 1856 | 1872 | ||
| 1857 | 1873 | ||
| 1858 | 1874 | fs.mkdtempSync = function(prefix, options) { | |
| 1859 | - if (!prefix || typeof prefix !== 'string') | ||
| 1860 | - throw new TypeError('filename prefix is required'); | ||
| 1875 | + if (!prefix || typeof prefix !== 'string') { | ||
| 1876 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 1877 | + 'prefix', | ||
| 1878 | + 'string', | ||
| 1879 | + prefix); | ||
| 1880 | + } | ||
| 1861 | 1881 | options = getOptions(options, {}); | |
| 1862 | 1882 | nullCheck(prefix); | |
| 1863 | 1883 | return binding.mkdtemp(prefix + 'XXXXXX', options.encoding); | |
@@ -1903,16 +1923,26 @@ function ReadStream(path, options) { | |||
| 1903 | 1923 | ||
| 1904 | 1924 | if (this.start !== undefined) { | |
| 1905 | 1925 | if (typeof this.start !== 'number') { | |
| 1906 | - throw new TypeError('"start" option must be a Number'); | ||
| 1926 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 1927 | + 'start', | ||
| 1928 | + 'number', | ||
| 1929 | + this.start); | ||
| 1907 | 1930 | } | |
| 1908 | 1931 | if (this.end === undefined) { | |
| 1909 | 1932 | this.end = Infinity; | |
| 1910 | 1933 | } else if (typeof this.end !== 'number') { | |
| 1911 | - throw new TypeError('"end" option must be a Number'); | ||
| 1934 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 1935 | + 'end', | ||
| 1936 | + 'number', | ||
| 1937 | + this.end); | ||
| 1912 | 1938 | } | |
| 1913 | 1939 | ||
| 1914 | 1940 | if (this.start > this.end) { | |
| 1915 | - throw new Error('"start" option must be <= "end" option'); | ||
| 1941 | + const errVal = `{start: ${this.start}, end: ${this.end}}`; | ||
| 1942 | + throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', | ||
| 1943 | + 'start', | ||
| 1944 | + '<= "end"', | ||
| 1945 | + errVal); | ||
| 1916 | 1946 | } | |
| 1917 | 1947 | ||
| 1918 | 1948 | this.pos = this.start; | |
@@ -2069,10 +2099,17 @@ function WriteStream(path, options) { | |||
| 2069 | 2099 | ||
| 2070 | 2100 | if (this.start !== undefined) { | |
| 2071 | 2101 | if (typeof this.start !== 'number') { | |
| 2072 | - throw new TypeError('"start" option must be a Number'); | ||
| 2102 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 2103 | + 'start', | ||
| 2104 | + 'number', | ||
| 2105 | + this.start); | ||
| 2073 | 2106 | } | |
| 2074 | 2107 | if (this.start < 0) { | |
| 2075 | - throw new Error('"start" must be >= zero'); | ||
| 2108 | + const errVal = `{start: ${this.start}}`; | ||
| 2109 | + throw new errors.RangeError('ERR_VALUE_OUT_OF_RANGE', | ||
| 2110 | + 'start', | ||
| 2111 | + '>= 0', | ||
| 2112 | + errVal); | ||
| 2076 | 2113 | } | |
| 2077 | 2114 | ||
| 2078 | 2115 | this.pos = this.start; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -264,6 +264,9 @@ E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s'); | |||
| 264 | 264 | E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s'); | |
| 265 | 265 | E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type'); | |
| 266 | 266 | E('ERR_UNKNOWN_STREAM_TYPE', 'Unknown stream file type'); | |
| 267 | + E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => { | ||
| 268 | + return `The value of "${start}" must be ${end}. Received "${value}"`; | ||
| 269 | + }); | ||
| 267 | 270 | E('ERR_V8BREAKITERATOR', 'Full ICU data not installed. ' + | |
| 268 | 271 | 'See https://github.com/nodejs/node/wiki/Intl'); | |
| 269 | 272 | E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -176,12 +176,15 @@ function run_test_3() { | |||
| 176 | 176 | ||
| 177 | 177 | const run_test_4 = common.mustCall(function() { | |
| 178 | 178 | // Error: start must be >= zero | |
| 179 | - assert.throws( | ||
| 180 | - function() { | ||
| 181 | - fs.createWriteStream(filepath, { start: -5, flags: 'r+' }); | ||
| 182 | - }, | ||
| 183 | - /"start" must be/ | ||
| 184 | - ); | ||
| 179 | + const block = () => { | ||
| 180 | + fs.createWriteStream(filepath, { start: -5, flags: 'r+' }); | ||
| 181 | + }; | ||
| 182 | + const err = { | ||
| 183 | + code: 'ERR_VALUE_OUT_OF_RANGE', | ||
| 184 | + message: 'The value of "start" must be >= 0. Received "{start: -5}"', | ||
| 185 | + type: RangeError | ||
| 186 | + }; | ||
| 187 | + common.expectsError(block, err); | ||
| 185 | 188 | }); | |
| 186 | 189 | ||
| 187 | 190 | run_test_1(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,13 +85,23 @@ assert.throws(() => { | |||
| 85 | 85 | fs.access(100, fs.F_OK, common.mustNotCall()); | |
| 86 | 86 | }, /^TypeError: path must be a string or Buffer$/); | |
| 87 | 87 | ||
| 88 | - assert.throws(() => { | ||
| 89 | - fs.access(__filename, fs.F_OK); | ||
| 90 | - }, /^TypeError: "callback" argument must be a function$/); | ||
| 91 | - | ||
| 92 | - assert.throws(() => { | ||
| 93 | - fs.access(__filename, fs.F_OK, {}); | ||
| 94 | - }, /^TypeError: "callback" argument must be a function$/); | ||
| 88 | + common.expectsError( | ||
| 89 | + () => { | ||
| 90 | + fs.access(__filename, fs.F_OK); | ||
| 91 | + }, | ||
| 92 | + { | ||
| 93 | + code: 'ERR_INVALID_CALLBACK', | ||
| 94 | + type: TypeError | ||
| 95 | + }); | ||
| 96 | + | ||
| 97 | + common.expectsError( | ||
| 98 | + () => { | ||
| 99 | + fs.access(__filename, fs.F_OK, {}); | ||
| 100 | + }, | ||
| 101 | + { | ||
| 102 | + code: 'ERR_INVALID_CALLBACK', | ||
| 103 | + type: TypeError | ||
| 104 | + }); | ||
| 95 | 105 | ||
| 96 | 106 | assert.doesNotThrow(() => { | |
| 97 | 107 | fs.accessSync(__filename); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const fs = require('fs'); | |
| 5 | - const cbTypeError = /^TypeError: "callback" argument must be a function$/; | ||
| 6 | 5 | const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}]; | |
| 7 | 6 | ||
| 8 | 7 | const { sep } = require('path'); | |
@@ -24,7 +23,10 @@ assert.doesNotThrow(testMakeCallback()); | |||
| 24 | 23 | ||
| 25 | 24 | function invalidCallbackThrowsTests() { | |
| 26 | 25 | callbackThrowValues.forEach((value) => { | |
| 27 | - assert.throws(testMakeCallback(value), cbTypeError); | ||
| 26 | + common.expectsError(testMakeCallback(value), { | ||
| 27 | + code: 'ERR_INVALID_CALLBACK', | ||
| 28 | + type: TypeError | ||
| 29 | + }); | ||
| 28 | 30 | }); | |
| 29 | 31 | } | |
| 30 | 32 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const fs = require('fs'); | |
| 5 | - const cbTypeError = /^TypeError: "callback" argument must be a function$/; | ||
| 6 | 5 | const callbackThrowValues = [null, true, false, 0, 1, 'foo', /foo/, [], {}]; | |
| 7 | 6 | const warn = 'Calling an asynchronous function without callback is deprecated.'; | |
| 8 | 7 | ||
@@ -23,7 +22,10 @@ assert.doesNotThrow(testMakeStatsCallback()); | |||
| 23 | 22 | ||
| 24 | 23 | function invalidCallbackThrowsTests() { | |
| 25 | 24 | callbackThrowValues.forEach((value) => { | |
| 26 | - assert.throws(testMakeStatsCallback(value), cbTypeError); | ||
| 25 | + common.expectsError(testMakeStatsCallback(value), { | ||
| 26 | + code: 'ERR_INVALID_CALLBACK', | ||
| 27 | + type: TypeError | ||
| 28 | + }); | ||
| 27 | 29 | }); | |
| 28 | 30 | } | |
| 29 | 31 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,22 +1,29 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | - const assert = require('assert'); | ||
| 4 | 3 | const fs = require('fs'); | |
| 5 | 4 | ||
| 6 | - const expectedError = /^TypeError: filename prefix is required$/; | ||
| 7 | 5 | const prefixValues = [undefined, null, 0, true, false, 1, '']; | |
| 8 | 6 | ||
| 9 | 7 | function fail(value) { | |
| 10 | - assert.throws( | ||
| 11 | - () => fs.mkdtempSync(value, {}), | ||
| 12 | - expectedError | ||
| 13 | - ); | ||
| 8 | + common.expectsError( | ||
| 9 | + () => { | ||
| 10 | + fs.mkdtempSync(value, {}); | ||
| 11 | + }, | ||
| 12 | + { | ||
| 13 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 14 | + type: TypeError | ||
| 15 | + }); | ||
| 14 | 16 | } | |
| 15 | 17 | ||
| 16 | 18 | function failAsync(value) { | |
| 17 | - assert.throws( | ||
| 18 | - () => fs.mkdtemp(value, common.mustNotCall()), expectedError | ||
| 19 | - ); | ||
| 19 | + common.expectsError( | ||
| 20 | + () => { | ||
| 21 | + fs.mkdtemp(value, common.mustNotCall()); | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 25 | + type: TypeError | ||
| 26 | + }); | ||
| 20 | 27 | } | |
| 21 | 28 | ||
| 22 | 29 | prefixValues.forEach((prefixValue) => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,20 +13,32 @@ fs.writeFileSync(tempFile, 'abc\ndef'); | |||
| 13 | 13 | const sanity = 'def'; | |
| 14 | 14 | const saneEmitter = fs.createReadStream(tempFile, { start: 4, end: 6 }); | |
| 15 | 15 | ||
| 16 | - assert.throws(function() { | ||
| 17 | - fs.createReadStream(tempFile, { start: '4', end: 6 }); | ||
| 18 | - }, /^TypeError: "start" option must be a Number$/, | ||
| 19 | - "start as string didn't throw an error for createReadStream"); | ||
| 16 | + common.expectsError( | ||
| 17 | + () => { | ||
| 18 | + fs.createReadStream(tempFile, { start: '4', end: 6 }); | ||
| 19 | + }, | ||
| 20 | + { | ||
| 21 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 22 | + type: TypeError | ||
| 23 | + }); | ||
| 20 | 24 | ||
| 21 | - assert.throws(function() { | ||
| 22 | - fs.createReadStream(tempFile, { start: 4, end: '6' }); | ||
| 23 | - }, /^TypeError: "end" option must be a Number$/, | ||
| 24 | - "end as string didn't throw an error for createReadStream"); | ||
| 25 | + common.expectsError( | ||
| 26 | + () => { | ||
| 27 | + fs.createReadStream(tempFile, { start: 4, end: '6' }); | ||
| 28 | + }, | ||
| 29 | + { | ||
| 30 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 31 | + type: TypeError | ||
| 32 | + }); | ||
| 25 | 33 | ||
| 26 | - assert.throws(function() { | ||
| 27 | - fs.createWriteStream(tempFile, { start: '4' }); | ||
| 28 | - }, /^TypeError: "start" option must be a Number$/, | ||
| 29 | - "start as string didn't throw an error for createWriteStream"); | ||
| 34 | + common.expectsError( | ||
| 35 | + () => { | ||
| 36 | + fs.createWriteStream(tempFile, { start: '4' }); | ||
| 37 | + }, | ||
| 38 | + { | ||
| 39 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 40 | + type: TypeError | ||
| 41 | + }); | ||
| 30 | 42 | ||
| 31 | 43 | saneEmitter.on('data', common.mustCall(function(data) { | |
| 32 | 44 | assert.strictEqual( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,17 +26,27 @@ const fs = require('fs'); | |||
| 26 | 26 | const URL = require('url').URL; | |
| 27 | 27 | ||
| 28 | 28 | function check(async, sync) { | |
| 29 | - const expected = /Path must be a string without null bytes/; | ||
| 30 | 29 | const argsSync = Array.prototype.slice.call(arguments, 2); | |
| 31 | 30 | const argsAsync = argsSync.concat((er) => { | |
| 32 | - assert(er && expected.test(er.message)); | ||
| 33 | - assert.strictEqual(er.code, 'ENOENT'); | ||
| 31 | + common.expectsError( | ||
| 32 | + () => { | ||
| 33 | + throw er; | ||
| 34 | + }, | ||
| 35 | + { | ||
| 36 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 37 | + type: Error | ||
| 38 | + }); | ||
| 34 | 39 | }); | |
| 35 | 40 | ||
| 36 | 41 | if (sync) { | |
| 37 | - assert.throws(() => { | ||
| 38 | - sync.apply(null, argsSync); | ||
| 39 | - }, expected); | ||
| 42 | + common.expectsError( | ||
| 43 | + () => { | ||
| 44 | + sync.apply(null, argsSync); | ||
| 45 | + }, | ||
| 46 | + { | ||
| 47 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 48 | + type: Error, | ||
| 49 | + }); | ||
| 40 | 50 | } | |
| 41 | 51 | ||
| 42 | 52 | if (async) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments