Mark G
Mark G3w ago

Dealing with errors in Response streams?

I've encountered problems whilst attempting to stream Responses, and discovered that if an error is thrown within the stream it just seems to be completely swallowed. Here's a simple example:
#!/usr/bin/env -S deno run --allow-net --watch

await Deno.serve(() => {
return new Response(ReadableStream.from(content()));
}).finished;

// deno-lint-ignore require-yield
function* content() {
throw new Error("EPIC FAIL");
}
#!/usr/bin/env -S deno run --allow-net --watch

await Deno.serve(() => {
return new Response(ReadableStream.from(content()));
}).finished;

// deno-lint-ignore require-yield
function* content() {
throw new Error("EPIC FAIL");
}
Hit the server and the request fails, but no errors are logged. Is there a preferred way to handle the errors in a stream? Or this is a bug in Deno? IMHO it feels like one, I wouldn't expects errors to just silently vanish like this.
3 Replies
Mark G
Mark GOP3w ago
Ok, I think this is definitely a bug, a runtime should never silently discard an unhandled error.
Mark G
Mark GOP3w ago
It appears to have been reported before, so I've updated the ticket... https://github.com/denoland/deno/issues/19867
GitHub
Error in ReadableStream/TransformStream is swallowed in Deno.serve ...
The following Deno.serve code has a subtle error (toUppperCase -> toUpperCase). When running this code, there is nothing to implicate the failing TransformStream handler. Deno.serve((req) => ...
Mark G
Mark GOP3w ago
So, apart from the fact there may actually be a bug in Deno regarding the discarding of unhandled errors, is there a way to gracefully handle potential errors from streams in the web streams API?

Did you find this page helpful?