Re: [whatwg/streams] Should write() always error the stream when it rejects the promise it returned? (#476)

Hmm, interesting. I think the BYOB design is good... it tries to distinguish between two types of errors:

- This particular chunk is bad and I won't allow it.
- I tried to write, but doing so failed, and you probably should not try again; treat this as broken.

I guess right now we do not support this distinction very well in the underlying sink/controller API. For example, let's say you wanted to implement a writable stream that only accepted strings, or bytes, or something. I think it would be good to reject a particular write, without necessarily killing the entire writable stream. But right now all you can do is return a rejected promise, which will cause the stream to become errored.

I see a few options:

- Say that if you fail validation, we should just error the whole stream. Probably for BYOB read() too. You screwed up and you don't get to recover. This is nice and simple, at least.
- Allow separate validation and erroring capabilities.  I guess the most natural way to do this is to say that returning a rejected promise from write() does not error the stream, and you have to do that with a separate controller.error() call?

There is also a gray area. If a write fails, not because of the producer's fault, but because of some transient issue, then it is simpler to error the stream---we probably should not let them continue writing, as they might skip a chunk that's important.

Hmm, that kind of logic is moving me more toward the "error the whole stream" option. E.g. consider if you had a program error that somehow ended up with chunks [string1, string2, blob3, string4, string5]. Probably it would be better to write string1 + string2 then get an errored writable stream, than to write string1 + string2 + string4 + string5 and only get the error notification on the one write.

Also, part of this comes down to, what do the underlying sink APIs look like? Looking through http://man7.org/linux/man-pages/man2/write.2.html#ERRORS it seems to me like most of these are not recoverable.

So for writable streams error-forever may be better. For BYOB it seems a bit less clear since I don't think there's the possibility of that kind of skipping and of missing error notifications. So maybe the asymmetry is OK?

---
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/476#issuecomment-230853562

Received on Wednesday, 6 July 2016 17:58:55 UTC