Re: [whatwg/streams] Is it bad that readableController.error() throws but writableController.error() no-ops in non-readable/writable states? (#821)

**Short answer:** I think we should probably change it.
**Long answer:** I don't think we ever discussed changing this for readable streams.

I think there are 4 principles at play here:

1. Do not punish the developer for things beyond their control. In particular, the exact timing of calls to the controller API vs. the reader API is outside the control of the underlying source developer, so having different behaviour based on ordering hurts predictability.
2. Don't report errors that are not helpful or actionable.
3. Consistency.
4. Compatibility.

The situation **is** different between readable and writable streams. In a writable stream, `writer.close()` or `writer.abort()` may have been called but not notified to the underlying sink yet. In the case of readable streams, they can only be errored by the underlying source itself, so calling `controller.error()` in the errored state is most likely a bug in the implementation of the underlying source. `readable.cancel()`, `reader.cancel()` or `readable.pipeTo()` can result in the stream being closed, but in all these cases `underlyingSource.cancel()` is called synchronously, meaning the source has an opportunity to avoid calling `controller.error()`.

Moving on to the second principle, informing the developer that they've accidentally called `controller.error()` twice is helpful. I think this is good justification for the way it is today, but transform streams change things. They makes the inconsistency between readable and writable streams more obvious and painful.

In a transform stream, there are other things that can error the readable besides `controller.error()`. Which means that it becomes very unhelpful for it to throw if the stream is already errored. But the transform stream controller behaves roughly like a wrapper around the readable controller, so having different behaviour here would be confusing.

In terms of compatibility, I don't think it would break much to change the behaviour of the readable stream `controller.error()`. Normal correct code shouldn't have been tripping the exception anyway.

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

Received on Tuesday, 3 October 2017 12:37:48 UTC