| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1f8d527 commit 7489141
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -609,6 +609,12 @@ also able to define their own types when using the public embedder API. | |||
| 609 | 609 | ||
| 610 | 610 | Used when attempting to perform an operation outside the bounds of a `Buffer`. | |
| 611 | 611 | ||
| 612 | + <a id="ERR_BUFFER_TOO_LARGE"></a> | ||
| 613 | + ### ERR_BUFFER_TOO_LARGE | ||
| 614 | + | ||
| 615 | + Used when an attempt has been made to create a `Buffer` larger than the | ||
| 616 | + maximum allowed size. | ||
| 617 | + | ||
| 612 | 618 | <a id="ERR_CHILD_CLOSED_BEFORE_REPLY"></a> | |
| 613 | 619 | ### ERR_CHILD_CLOSED_BEFORE_REPLY | |
| 614 | 620 | ||
@@ -879,6 +885,12 @@ Used when a given index is out of the accepted range (e.g. negative offsets). | |||
| 879 | 885 | Used generically to identify that an argument of the wrong type has been passed | |
| 880 | 886 | to a Node.js API. | |
| 881 | 887 | ||
| 888 | + <a id="ERR_INVALID_ARG_VALUE"></a> | ||
| 889 | + ### ERR_INVALID_ARG_VALUE | ||
| 890 | + | ||
| 891 | + Used generically to identify that an invalid or unsupported value has been | ||
| 892 | + passed for a given argument. | ||
| 893 | + | ||
| 882 | 894 | <a id="ERR_INVALID_ARRAY_LENGTH"></a> | |
| 883 | 895 | ### ERR_INVALID_ARRAY_LENGTH | |
| 884 | 896 | ||
@@ -1277,6 +1289,12 @@ entry types were found. | |||
| 1277 | 1289 | ||
| 1278 | 1290 | Used when a given value is out of the accepted range. | |
| 1279 | 1291 | ||
| 1292 | + <a id="ERR_ZLIB_BINDING_CLOSED"></a> | ||
| 1293 | + ### ERR_ZLIB_BINDING_CLOSED | ||
| 1294 | + | ||
| 1295 | + Used when an attempt is made to use a `zlib` object after it has already been | ||
| 1296 | + closed. | ||
| 1297 | + | ||
| 1280 | 1298 | [`ERR_INVALID_ARG_TYPE`]: #ERR_INVALID_ARG_TYPE | |
| 1281 | 1299 | [`subprocess.kill()`]: child_process.html#child_process_subprocess_kill_signal | |
| 1282 | 1300 | [`subprocess.send()`]: child_process.html#child_process_subprocess_send_message_sendhandle_options_callback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,10 @@ | |||
| 11 | 11 | const kCode = Symbol('code'); | |
| 12 | 12 | const messages = new Map(); | |
| 13 | 13 | ||
| 14 | + const { | ||
| 15 | + kMaxLength | ||
| 16 | + } = process.binding('buffer'); | ||
| 17 | + | ||
| 14 | 18 | // Lazily loaded | |
| 15 | 19 | var util = null; | |
| 16 | 20 | ||
@@ -121,6 +125,8 @@ E('ERR_ASSERTION', '%s'); | |||
| 121 | 125 | E('ERR_ASYNC_CALLBACK', (name) => `${name} must be a function`); | |
| 122 | 126 | E('ERR_ASYNC_TYPE', (s) => `Invalid name for async "type": ${s}`); | |
| 123 | 127 | E('ERR_BUFFER_OUT_OF_BOUNDS', bufferOutOfBounds); | |
| 128 | + E('ERR_BUFFER_TOO_LARGE', | ||
| 129 | + `Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes`); | ||
| 124 | 130 | E('ERR_CHILD_CLOSED_BEFORE_REPLY', 'Child closed before reply received'); | |
| 125 | 131 | E('ERR_CONSOLE_WRITABLE_STREAM', | |
| 126 | 132 | 'Console expects a writable stream instance for %s'); | |
@@ -206,6 +212,10 @@ E('ERR_HTTP_TRAILER_INVALID', | |||
| 206 | 212 | 'Trailers are invalid with this transfer encoding'); | |
| 207 | 213 | E('ERR_INDEX_OUT_OF_RANGE', 'Index out of range'); | |
| 208 | 214 | E('ERR_INVALID_ARG_TYPE', invalidArgType); | |
| 215 | + E('ERR_INVALID_ARG_VALUE', | ||
| 216 | + (name, value) => { | ||
| 217 | + return `The value "${String(value)}" is invalid for argument "${name}"`; | ||
| 218 | + }); | ||
| 209 | 219 | E('ERR_INVALID_ARRAY_LENGTH', | |
| 210 | 220 | (name, len, actual) => { | |
| 211 | 221 | internalAssert(typeof actual === 'number', 'actual must be a number'); | |
@@ -303,6 +313,7 @@ E('ERR_VALID_PERFORMANCE_ENTRY_TYPE', | |||
| 303 | 313 | E('ERR_VALUE_OUT_OF_RANGE', (start, end, value) => { | |
| 304 | 314 | return `The value of "${start}" must be ${end}. Received "${value}"`; | |
| 305 | 315 | }); | |
| 316 | + E('ERR_ZLIB_BINDING_CLOSED', 'zlib binding closed'); | ||
| 306 | 317 | ||
| 307 | 318 | function invalidArgType(name, expected, actual) { | |
| 308 | 319 | internalAssert(name, 'name is required'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,15 +21,16 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | ||
| 24 | - const Buffer = require('buffer').Buffer; | ||
| 24 | + const errors = require('internal/errors'); | ||
| 25 | 25 | const Transform = require('_stream_transform'); | |
| 26 | 26 | const { _extend } = require('util'); | |
| 27 | 27 | const { isArrayBufferView } = require('internal/util/types'); | |
| 28 | 28 | const binding = process.binding('zlib'); | |
| 29 | 29 | const assert = require('assert').ok; | |
| 30 | - const kMaxLength = require('buffer').kMaxLength; | ||
| 31 | - const kRangeErrorMessage = 'Cannot create final Buffer. It would be larger ' + | ||
| 32 | - `than 0x${kMaxLength.toString(16)} bytes`; | ||
| 30 | + const { | ||
| 31 | + Buffer, | ||
| 32 | + kMaxLength | ||
| 33 | + } = require('buffer'); | ||
| 33 | 34 | ||
| 34 | 35 | const constants = process.binding('constants').zlib; | |
| 35 | 36 | const { | |
@@ -93,7 +94,7 @@ function zlibBufferOnEnd() { | |||
| 93 | 94 | var buf; | |
| 94 | 95 | var err; | |
| 95 | 96 | if (this.nread >= kMaxLength) { | |
| 96 | - err = new RangeError(kRangeErrorMessage); | ||
| 97 | + err = new errors.RangeError('ERR_BUFFER_TOO_LARGE'); | ||
| 97 | 98 | } else { | |
| 98 | 99 | var bufs = this.buffers; | |
| 99 | 100 | buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread)); | |
@@ -111,8 +112,9 @@ function zlibBufferSync(engine, buffer) { | |||
| 111 | 112 | if (typeof buffer === 'string') { | |
| 112 | 113 | buffer = Buffer.from(buffer); | |
| 113 | 114 | } else if (!isArrayBufferView(buffer)) { | |
| 114 | - throw new TypeError('"buffer" argument must be a string, Buffer, ' + | ||
| 115 | - 'TypedArray, or DataView'); | ||
| 115 | + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', | ||
| 116 | + 'buffer', | ||
| 117 | + ['string', 'Buffer', 'TypedArray', 'DataView']); | ||
| 116 | 118 | } | |
| 117 | 119 | buffer = processChunkSync(engine, buffer, engine._finishFlushFlag); | |
| 118 | 120 | if (engine._info) | |
@@ -128,7 +130,7 @@ function zlibOnError(message, errno) { | |||
| 128 | 130 | _close(self); | |
| 129 | 131 | self._hadError = true; | |
| 130 | 132 | ||
| 131 | - var error = new Error(message); | ||
| 133 | + const error = new Error(message); | ||
| 132 | 134 | error.errno = errno; | |
| 133 | 135 | error.code = codes[errno]; | |
| 134 | 136 | self.emit('error', error); | |
@@ -163,15 +165,17 @@ function Zlib(opts, mode) { | |||
| 163 | 165 | chunkSize = opts.chunkSize; | |
| 164 | 166 | if (chunkSize !== undefined && chunkSize === chunkSize) { | |
| 165 | 167 | if (chunkSize < Z_MIN_CHUNK || !Number.isFinite(chunkSize)) | |
| 166 | - throw new RangeError('Invalid chunk size: ' + chunkSize); | ||
| 168 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', | ||
| 169 | + 'chunkSize', | ||
| 170 | + chunkSize); | ||
| 167 | 171 | } else { | |
| 168 | 172 | chunkSize = Z_DEFAULT_CHUNK; | |
| 169 | 173 | } | |
| 170 | 174 | ||
| 171 | 175 | flush = opts.flush; | |
| 172 | 176 | if (flush !== undefined && flush === flush) { | |
| 173 | 177 | if (flush < Z_NO_FLUSH || flush > Z_BLOCK || !Number.isFinite(flush)) | |
| 174 | - throw new RangeError('Invalid flush flag: ' + flush); | ||
| 178 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', 'flush', flush); | ||
| 175 | 179 | } else { | |
| 176 | 180 | flush = Z_NO_FLUSH; | |
| 177 | 181 | } | |
@@ -180,7 +184,9 @@ function Zlib(opts, mode) { | |||
| 180 | 184 | if (finishFlush !== undefined && finishFlush === finishFlush) { | |
| 181 | 185 | if (finishFlush < Z_NO_FLUSH || finishFlush > Z_BLOCK || | |
| 182 | 186 | !Number.isFinite(finishFlush)) { | |
| 183 | - throw new RangeError('Invalid flush flag: ' + finishFlush); | ||
| 187 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', | ||
| 188 | + 'finishFlush', | ||
| 189 | + finishFlush); | ||
| 184 | 190 | } | |
| 185 | 191 | } else { | |
| 186 | 192 | finishFlush = Z_FINISH; | |
@@ -190,7 +196,9 @@ function Zlib(opts, mode) { | |||
| 190 | 196 | if (windowBits !== undefined && windowBits === windowBits) { | |
| 191 | 197 | if (windowBits < Z_MIN_WINDOWBITS || windowBits > Z_MAX_WINDOWBITS || | |
| 192 | 198 | !Number.isFinite(windowBits)) { | |
| 193 | - throw new RangeError('Invalid windowBits: ' + windowBits); | ||
| 199 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', | ||
| 200 | + 'windowBits', | ||
| 201 | + windowBits); | ||
| 194 | 202 | } | |
| 195 | 203 | } else { | |
| 196 | 204 | windowBits = Z_DEFAULT_WINDOWBITS; | |
@@ -200,7 +208,8 @@ function Zlib(opts, mode) { | |||
| 200 | 208 | if (level !== undefined && level === level) { | |
| 201 | 209 | if (level < Z_MIN_LEVEL || level > Z_MAX_LEVEL || | |
| 202 | 210 | !Number.isFinite(level)) { | |
| 203 | - throw new RangeError('Invalid compression level: ' + level); | ||
| 211 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', | ||
| 212 | + 'level', level); | ||
| 204 | 213 | } | |
| 205 | 214 | } else { | |
| 206 | 215 | level = Z_DEFAULT_COMPRESSION; | |
@@ -210,7 +219,8 @@ function Zlib(opts, mode) { | |||
| 210 | 219 | if (memLevel !== undefined && memLevel === memLevel) { | |
| 211 | 220 | if (memLevel < Z_MIN_MEMLEVEL || memLevel > Z_MAX_MEMLEVEL || | |
| 212 | 221 | !Number.isFinite(memLevel)) { | |
| 213 | - throw new RangeError('Invalid memLevel: ' + memLevel); | ||
| 222 | + throw new errors.RangeError('ERR_INVALID_OPT_VALUE', | ||
| 223 | + 'memLevel', memLevel); | ||
| 214 | 224 | } | |
| 215 | 225 | } else { | |
| 216 | 226 | memLevel = Z_DEFAULT_MEMLEVEL; | |
@@ -220,16 +230,18 @@ function Zlib(opts, mode) { | |||
| 220 | 230 | if (strategy !== undefined && strategy === strategy) { | |
| 221 | 231 | if (strategy < Z_DEFAULT_STRATEGY || strategy > Z_FIXED || | |
| 222 | 232 | !Number.isFinite(strategy)) { | |
| 223 | - throw new TypeError('Invalid strategy: ' + strategy); | ||
| 233 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', | ||
| 234 | + 'strategy', strategy); | ||
| 224 | 235 | } | |
| 225 | 236 | } else { | |
| 226 | 237 | strategy = Z_DEFAULT_STRATEGY; | |
| 227 | 238 | } | |
| 228 | 239 | ||
| 229 | 240 | dictionary = opts.dictionary; | |
| 230 | 241 | if (dictionary !== undefined && !isArrayBufferView(dictionary)) { | |
| 231 | - throw new TypeError( | ||
| 232 | - 'Invalid dictionary: it should be a Buffer, TypedArray, or DataView'); | ||
| 242 | + throw new errors.TypeError('ERR_INVALID_OPT_VALUE', | ||
| 243 | + 'dictionary', | ||
| 244 | + dictionary); | ||
| 233 | 245 | } | |
| 234 | 246 | ||
| 235 | 247 | if (opts.encoding || opts.objectMode || opts.writableObjectMode) { | |
@@ -273,12 +285,12 @@ Object.defineProperty(Zlib.prototype, '_closed', { | |||
| 273 | 285 | ||
| 274 | 286 | Zlib.prototype.params = function params(level, strategy, callback) { | |
| 275 | 287 | if (level < Z_MIN_LEVEL || level > Z_MAX_LEVEL) | |
| 276 | - throw new RangeError('Invalid compression level: ' + level); | ||
| 288 | + throw new errors.RangeError('ERR_INVALID_ARG_VALUE', 'level', level); | ||
| 277 | 289 | ||
| 278 | 290 | if (strategy !== undefined && | |
| 279 | 291 | (strategy < Z_DEFAULT_STRATEGY || strategy > Z_FIXED || | |
| 280 | 292 | !Number.isFinite(strategy))) { | |
| 281 | - throw new TypeError('Invalid strategy: ' + strategy); | ||
| 293 | + throw new errors.TypeError('ERR_INVALID_ARG_VALUE', 'strategy', strategy); | ||
| 282 | 294 | } | |
| 283 | 295 | ||
| 284 | 296 | if (this._level !== level || this._strategy !== strategy) { | |
@@ -455,7 +467,7 @@ function processChunkSync(self, chunk, flushFlag) { | |||
| 455 | 467 | ||
| 456 | 468 | if (nread >= kMaxLength) { | |
| 457 | 469 | _close(self); | |
| 458 | - throw new RangeError(kRangeErrorMessage); | ||
| 470 | + throw new errors.RangeError('ERR_BUFFER_TOO_LARGE'); | ||
| 459 | 471 | } | |
| 460 | 472 | ||
| 461 | 473 | _close(self); | |
@@ -466,7 +478,7 @@ function processChunkSync(self, chunk, flushFlag) { | |||
| 466 | 478 | function processChunk(self, chunk, flushFlag, cb) { | |
| 467 | 479 | var handle = self._handle; | |
| 468 | 480 | if (!handle) | |
| 469 | - return cb(new Error('zlib binding closed')); | ||
| 481 | + return cb(new errors.Error('ERR_ZLIB_BINDING_CLOSED')); | ||
| 470 | 482 | ||
| 471 | 483 | handle.buffer = chunk; | |
| 472 | 484 | handle.cb = cb; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -284,3 +284,20 @@ assert.strictEqual( | |||
| 284 | 284 | assert.strictEqual( | |
| 285 | 285 | errors.message('ERR_INVALID_ASYNC_ID', ['asyncId', undefined]), | |
| 286 | 286 | 'Invalid asyncId value: undefined'); | |
| 287 | + | ||
| 288 | + { | ||
| 289 | + const { kMaxLength } = process.binding('buffer'); | ||
| 290 | + const error = new errors.Error('ERR_BUFFER_TOO_LARGE'); | ||
| 291 | + assert.strictEqual( | ||
| 292 | + error.message, | ||
| 293 | + `Cannot create a Buffer larger than 0x${kMaxLength.toString(16)} bytes` | ||
| 294 | + ); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + { | ||
| 298 | + const error = new errors.Error('ERR_INVALID_ARG_VALUE', 'foo', 'bar'); | ||
| 299 | + assert.strictEqual( | ||
| 300 | + error.message, | ||
| 301 | + 'The value "bar" is invalid for argument "foo"' | ||
| 302 | + ); | ||
| 303 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments