Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non readable stream should throw when errored while not readable #39756

Closed
ronag opened this issue Aug 13, 2021 · 6 comments · Fixed by mdn/content#13581
Closed

Non readable stream should throw when errored while not readable #39756

ronag opened this issue Aug 13, 2021 · 6 comments · Fixed by mdn/content#13581

Comments

@ronag
Copy link
Member

ronag commented Aug 13, 2021

https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultController/error#exceptions

TypeError
The source object is not a ReadableStreamDefaultController, or the stream is not readable for some other reason.

const { ReadableStream } = require('stream/web')

let c
const s = new ReadableStream({
  start (controller) {
    c = controller
  }
})

c.close()

try {
  c.error()
} catch (err) {
  console.error(err) // This should log an error
}
@ronag
Copy link
Member Author

ronag commented Aug 13, 2021

@jasnell @nodejs/streams

@ofirbarak
Copy link
Contributor

But it says also we can call error even when the stream is not readable. Maybe a mistake in the doc?

@aduh95
Copy link
Contributor

aduh95 commented Mar 6, 2022

The above snippet doesn't log an error in any of the WHATWG stream implementation (I've tried Deno, Firefox, Safari, and Chromium), whatever the spec says I think we're good as long as all the implementation are aligned.

@aduh95
Copy link
Contributor

aduh95 commented Mar 6, 2022

Maybe the MDN page is wrong, looking at the spec it says:

The error(e) method steps are:
Perform ! ReadableStreamDefaultControllerError(this, e).

ReadableStreamDefaultControllerError(controller, e) performs the following steps:
Let stream be controller.[[stream]].

If stream.[[state]] is not "readable", return.

Perform ! ResetQueue(controller).

Perform ! ReadableStreamDefaultControllerClearAlgorithms(controller).

Perform ! ReadableStreamError(stream, e).

It says the method should return, not throw an exception. I'll open a PR to mdn/content to fix the page.

@jasnell
Copy link
Member

jasnell commented Mar 6, 2022

Yeah, as surprising as it may be, the behavior here is correct and MDN is wrong.

@aduh95
Copy link
Contributor

aduh95 commented Mar 6, 2022

Fixed by mdn/content#13581.

@aduh95 aduh95 closed this as completed Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants