Shouldn't WritableStreamDefaultWriter.write() reject if underlyingSink.write calls controller.error()? #1332
Open
Description
What is the issue with the Streams Standard?
I admit that I don't fully understand what the standard says should happen here. But Chrome and Node both have the same behavior in this case and it seems wrong. In both, WritableStreamDefaultWriter.write()
resolves when underlyingSink.write()
calls controller.error()
, but rejects when underlyingSink.write()
throws or returns a Promise that rejects.
Why shouldn't WritableStreamDefaultWriter.write()
reject in all cases?
{
const stream = new WritableStream({
write(chunk, controller) {
controller.error(new Error('test'))
},
})
const writer = stream.getWriter()
writer.write().then(
() => console.error('with controller.error: resolved'), // this is what happens
(error) => console.error('with controller.error: rejected', error)
)
}
{
const stream = new WritableStream({
write(chunk, controller) {
throw new Error('test')
},
})
const writer = stream.getWriter()
writer.write().then(
() => console.error('with throw: resolved'),
(error) => console.error('with throw: rejected', error) // this is what happens
)
}
{
const stream = new WritableStream({
async write(chunk, controller) {
throw new Error('test')
},
})
const writer = stream.getWriter()
writer.write().then(
() => console.error('with reject: resolved'),
(error) => console.error('with reject: rejected', error) // this is what happens
)
}
Node
with controller.error: resolved
with throw: rejected Error: test
at Object.write (/Users/andy/gh/web-streams-finally/src/temp.js:17:13)
at invokePromiseCallback (node:internal/webstreams/util:162:10)
at node:internal/webstreams/util:167:23
at writableStreamDefaultControllerProcessWrite (node:internal/webstreams/writablestream:1129:5)
at writableStreamDefaultControllerAdvanceQueueIfNeeded (node:internal/webstreams/writablestream:1244:5)
at node:internal/webstreams/writablestream:1318:7
with reject: rejected Error: test
at Object.write (/Users/andy/gh/web-streams-finally/src/temp.js:30:13)
at invokePromiseCallback (node:internal/webstreams/util:162:10)
at node:internal/webstreams/util:167:23
at writableStreamDefaultControllerProcessWrite (node:internal/webstreams/writablestream:1129:5)
at writableStreamDefaultControllerAdvanceQueueIfNeeded (node:internal/webstreams/writablestream:1244:5)
at node:internal/webstreams/writablestream:1318:7
Browser
VM172:9 with controller.error: resolved
VM172:23 with throw: rejected Error: test
VM172:36 with reject: rejected Error: test
Metadata
Assignees
Labels
No labels