diff options
Diffstat (limited to 'std/io')
-rw-r--r-- | std/io/bufio.ts | 8 | ||||
-rw-r--r-- | std/io/bufio_test.ts | 6 | ||||
-rw-r--r-- | std/io/iotest.ts | 11 | ||||
-rw-r--r-- | std/io/ioutil.ts | 8 |
4 files changed, 13 insertions, 20 deletions
diff --git a/std/io/bufio.ts b/std/io/bufio.ts index fa0ba7e73..12b5c2d2b 100644 --- a/std/io/bufio.ts +++ b/std/io/bufio.ts @@ -21,11 +21,11 @@ export class BufferFullError extends Error { } } -export class UnexpectedEOFError extends Error { - name = "UnexpectedEOFError"; +export class PartialReadError extends Deno.errors.UnexpectedEof { + name = "PartialReadError"; partial?: Uint8Array; constructor() { - super("Unexpected EOF"); + super("Encountered UnexpectedEof, data only partially read"); } } @@ -178,7 +178,7 @@ export class BufReader implements Reader { if (bytesRead === 0) { return Deno.EOF; } else { - throw new UnexpectedEOFError(); + throw new PartialReadError(); } } bytesRead += rr; diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index 75bd7b40e..d925175f1 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -15,7 +15,7 @@ import { BufReader, BufWriter, BufferFullError, - UnexpectedEOFError, + PartialReadError, readStringDelim, readLines } from "./bufio.ts"; @@ -369,9 +369,9 @@ Deno.test(async function bufReaderReadFull(): Promise<void> { const buf = new Uint8Array(6); try { await bufr.readFull(buf); - fail("readFull() should throw"); + fail("readFull() should throw PartialReadError"); } catch (err) { - assert(err instanceof UnexpectedEOFError); + assert(err instanceof PartialReadError); assert(err.partial instanceof Uint8Array); assertEquals(err.partial.length, 5); assertEquals(dec.decode(buf.subarray(0, 5)), "World"); diff --git a/std/io/iotest.ts b/std/io/iotest.ts index 8d2cee6e2..1e922e33f 100644 --- a/std/io/iotest.ts +++ b/std/io/iotest.ts @@ -36,14 +36,7 @@ export class HalfReader implements Reader { } } -export class ErrTimeout extends Error { - constructor() { - super("timeout"); - this.name = "ErrTimeout"; - } -} - -/** TimeoutReader returns ErrTimeout on the second read +/** TimeoutReader returns `Deno.errors.TimedOut` on the second read * with no data. Subsequent calls to read succeed. */ export class TimeoutReader implements Reader { @@ -53,7 +46,7 @@ export class TimeoutReader implements Reader { async read(p: Uint8Array): Promise<number | Deno.EOF> { this.count++; if (this.count === 2) { - throw new ErrTimeout(); + throw new Deno.errors.TimedOut(); } return this.r.read(p); } diff --git a/std/io/ioutil.ts b/std/io/ioutil.ts index 83d639463..cfcfdf794 100644 --- a/std/io/ioutil.ts +++ b/std/io/ioutil.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -import { BufReader, UnexpectedEOFError } from "./bufio.ts"; +import { BufReader } from "./bufio.ts"; type Reader = Deno.Reader; type Writer = Deno.Writer; import { assert } from "../testing/asserts.ts"; @@ -37,7 +37,7 @@ export async function readShort(buf: BufReader): Promise<number | Deno.EOF> { const high = await buf.readByte(); if (high === Deno.EOF) return Deno.EOF; const low = await buf.readByte(); - if (low === Deno.EOF) throw new UnexpectedEOFError(); + if (low === Deno.EOF) throw new Deno.errors.UnexpectedEof(); return (high << 8) | low; } @@ -46,7 +46,7 @@ export async function readInt(buf: BufReader): Promise<number | Deno.EOF> { const high = await readShort(buf); if (high === Deno.EOF) return Deno.EOF; const low = await readShort(buf); - if (low === Deno.EOF) throw new UnexpectedEOFError(); + if (low === Deno.EOF) throw new Deno.errors.UnexpectedEof(); return (high << 16) | low; } @@ -57,7 +57,7 @@ export async function readLong(buf: BufReader): Promise<number | Deno.EOF> { const high = await readInt(buf); if (high === Deno.EOF) return Deno.EOF; const low = await readInt(buf); - if (low === Deno.EOF) throw new UnexpectedEOFError(); + if (low === Deno.EOF) throw new Deno.errors.UnexpectedEof(); const big = (BigInt(high) << 32n) | BigInt(low); // We probably should provide a similar API that returns BigInt values. if (big > MAX_SAFE_INTEGER) { |