[whatwg/streams] Shouldn't WritableStreamDefaultWriter.write() reject if underlyingSink.write calls controller.error()? (Issue #1332)

### What is the issue with the Streams Standard?

I admit I'm seeing this in Chrome and Node and haven't verified if they're fully conforming to the standard.  But they have the same behavior here and it seems wrong.  In both cases, `WritableStreamDefaultWriter.write()` resolves when `underlyingSink.write()` calls `controller.error()`, but rejects when it throws or returns a Promise that rejects.

Why shouldn't `WritableStreamDefaultWriter.write()` reject in all cases?

```js
{
  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
  )
}
```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1332
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/streams/issues/1332@github.com>

Received on Thursday, 21 November 2024 20:26:39 UTC