mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
chore(stream/conversion.ts): handle errors in toTransformStream
correctly (#2314)
This commit is contained in:
parent
f415da4c62
commit
4ab49091e9
@ -243,7 +243,7 @@ export function toTransformStream<I, O>(
|
||||
} catch (error) {
|
||||
// Propagate error to stream from iterator
|
||||
// If the stream status is "errored", it will be thrown, but ignore.
|
||||
await readable.cancel(error).catch();
|
||||
await readable.cancel(error).catch(() => {});
|
||||
controller.error(error);
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { assert, assertEquals } from "../testing/asserts.ts";
|
||||
import { assert, assertEquals, assertRejects } from "../testing/asserts.ts";
|
||||
import {
|
||||
copy,
|
||||
iterateReader,
|
||||
@ -350,7 +350,7 @@ Deno.test({
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[streams] toTransformStream() - iterable, not asynciterable",
|
||||
name: "[streams] toTransformStream() Pass iterable instead of asyncIterable",
|
||||
async fn() {
|
||||
const readable = readableStreamFromIterable([0, 1, 2])
|
||||
.pipeThrough(toTransformStream(function* (_src) {
|
||||
@ -523,6 +523,27 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name:
|
||||
"[streams] toTransformStream() Cancel streams with the correct error message",
|
||||
async fn() {
|
||||
const src = readableStreamFromIterable([0, 1, 2]);
|
||||
// deno-lint-ignore require-yield
|
||||
const transform = toTransformStream(function* (src) {
|
||||
src.getReader(); // lock the source stream to cause error at cancel
|
||||
throw new Error("foo");
|
||||
});
|
||||
|
||||
await assertRejects(
|
||||
async () => {
|
||||
for await (const _ of src.pipeThrough(transform));
|
||||
},
|
||||
Error,
|
||||
"foo",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
class MockReaderCloser implements Deno.Reader, Deno.Closer {
|
||||
chunks: Uint8Array[] = [];
|
||||
closeCall = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user