镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

@ronag

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
}

Activity

  1. added
    web streamsIssues and PRs related to the Web Streams API.
    on Aug 13, 2021
  2. ronag commented on Aug 13, 2021

    @ronag
    MemberAuthor

    @jasnell @nodejs/streams

  3. ofirbarak commented on Nov 21, 2021

    @ofirbarak
    Contributor

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

  4. aduh95 commented on Mar 6, 2022

    @aduh95
    Contributor

    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.

  5. aduh95 commented on Mar 6, 2022

    @aduh95
    Contributor

    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.

  6. jasnell commented on Mar 6, 2022

    @jasnell
    Member

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

  7. aduh95 commented on Mar 6, 2022

    @aduh95
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    web streamsIssues and PRs related to the Web Streams API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions