Skip to content

Commit 79c2bd5

Browse files
authored
refactor(streams): throw RangeError within Buffer methods (#6714)
1 parent 1f48367 commit 79c2bd5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

streams/buffer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class Buffer {
322322
return;
323323
}
324324
if (n < 0 || n > this.length) {
325-
throw new Error(
325+
throw new RangeError(
326326
`Buffer truncation value "${n}" is not between 0 and ${this.length}`,
327327
);
328328
}
@@ -383,7 +383,7 @@ export class Buffer {
383383
// don't spend all our time copying.
384384
copy(this.#buf.subarray(this.#off), this.#buf);
385385
} else if (c + n > MAX_SIZE) {
386-
throw new Error(
386+
throw new RangeError(
387387
`The buffer cannot grow beyond the maximum size of ${MAX_SIZE}`,
388388
);
389389
} else {
@@ -424,7 +424,7 @@ export class Buffer {
424424
*/
425425
grow(n: number) {
426426
if (n < 0) {
427-
throw new Error(
427+
throw new RangeError(
428428
`Cannot grow buffer as growth must be positive: received ${n}`,
429429
);
430430
}

streams/buffer_test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Deno.test("Buffer.truncate(n) throws if n is negative", () => {
5858
() => {
5959
buf.truncate(-1);
6060
},
61-
Error,
61+
RangeError,
6262
'Buffer truncation value "-1" is not between 0 and 0',
6363
);
6464
});
@@ -69,7 +69,7 @@ Deno.test("Buffer.truncate(n) throws if n is greater than the length of the buff
6969
() => {
7070
buf.truncate(1);
7171
},
72-
Error,
72+
RangeError,
7373
'Buffer truncation value "1" is not between 0 and 0',
7474
);
7575
});
@@ -115,7 +115,7 @@ Deno.test("Buffer.grow(n) throws an error if n is a negative value", () => {
115115
() => {
116116
buf.grow(-1);
117117
},
118-
Error,
118+
RangeError,
119119
"Cannot grow buffer as growth must be positive: received -1",
120120
);
121121
});
@@ -126,7 +126,7 @@ Deno.test("Buffer.grow(n) throws if the total of byte size exceeds 2 ** 32 - 2",
126126
() => {
127127
buf.grow(2 ** 32);
128128
},
129-
Error,
129+
RangeError,
130130
"The buffer cannot grow beyond the maximum size of",
131131
);
132132
});

0 commit comments

Comments
 (0)