zlib: use RangeError/TypeError consistently · nodejs/node@b514bd2 · GitHub
Skip to content

Commit b514bd2

Browse files
committed
zlib: use RangeError/TypeError consistently
PR-URL: #11391 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent 8e69f7e commit b514bd2

3 files changed

Lines changed: 30 additions & 28 deletions

File tree

lib/zlib.js

Lines changed: 16 additions & 14 deletions

test/parallel/test-zlib-deflate-constructors.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ assert.ok(new zlib.DeflateRaw() instanceof zlib.DeflateRaw);
1515
// Throws if `opts.chunkSize` is invalid
1616
assert.throws(
1717
() => { new zlib.Deflate({chunkSize: -Infinity}); },
18-
/^Error: Invalid chunk size: -Infinity$/
18+
/^RangeError: Invalid chunk size: -Infinity$/
1919
);
2020

2121
// Confirm that maximum chunk size cannot be exceeded because it is `Infinity`.
@@ -24,23 +24,23 @@ assert.strictEqual(zlib.constants.Z_MAX_CHUNK, Infinity);
2424
// Throws if `opts.windowBits` is invalid
2525
assert.throws(
2626
() => { new zlib.Deflate({windowBits: -Infinity}); },
27-
/^Error: Invalid windowBits: -Infinity$/
27+
/^RangeError: Invalid windowBits: -Infinity$/
2828
);
2929

3030
assert.throws(
3131
() => { new zlib.Deflate({windowBits: Infinity}); },
32-
/^Error: Invalid windowBits: Infinity$/
32+
/^RangeError: Invalid windowBits: Infinity$/
3333
);
3434

3535
// Throws if `opts.level` is invalid
3636
assert.throws(
3737
() => { new zlib.Deflate({level: -Infinity}); },
38-
/^Error: Invalid compression level: -Infinity$/
38+
/^RangeError: Invalid compression level: -Infinity$/
3939
);
4040

4141
assert.throws(
4242
() => { new zlib.Deflate({level: Infinity}); },
43-
/^Error: Invalid compression level: Infinity$/
43+
/^RangeError: Invalid compression level: Infinity$/
4444
);
4545

4646
// Throws a RangeError if `level` invalid in `Deflate.prototype.params()`
@@ -57,12 +57,12 @@ assert.throws(
5757
// Throws if `opts.memLevel` is invalid
5858
assert.throws(
5959
() => { new zlib.Deflate({memLevel: -Infinity}); },
60-
/^Error: Invalid memLevel: -Infinity$/
60+
/^RangeError: Invalid memLevel: -Infinity$/
6161
);
6262

6363
assert.throws(
6464
() => { new zlib.Deflate({memLevel: Infinity}); },
65-
/^Error: Invalid memLevel: Infinity$/
65+
/^RangeError: Invalid memLevel: Infinity$/
6666
);
6767

6868
// Does not throw if opts.strategy is valid
@@ -89,13 +89,13 @@ assert.doesNotThrow(
8989
// Throws if opt.strategy is the wrong type.
9090
assert.throws(
9191
() => { new zlib.Deflate({strategy: '' + zlib.constants.Z_RLE }); },
92-
/^Error: Invalid strategy: 3$/
92+
/^TypeError: Invalid strategy: 3$/
9393
);
9494

9595
// Throws if opts.strategy is invalid
9696
assert.throws(
9797
() => { new zlib.Deflate({strategy: 'this is a bogus strategy'}); },
98-
/^Error: Invalid strategy: this is a bogus strategy$/
98+
/^TypeError: Invalid strategy: this is a bogus strategy$/
9999
);
100100

101101
// Throws TypeError if `strategy` is invalid in `Deflate.prototype.params()`
@@ -107,5 +107,5 @@ assert.throws(
107107
// Throws if opts.dictionary is not a Buffer
108108
assert.throws(
109109
() => { new zlib.Deflate({dictionary: 'not a buffer'}); },
110-
/^Error: Invalid dictionary: it should be a Buffer instance$/
110+
/^TypeError: Invalid dictionary: it should be a Buffer instance$/
111111
);

test/parallel/test-zlib-flush-flags.js

Lines changed: 4 additions & 4 deletions

0 commit comments

Comments
 (0)