ReadableByteStreamController: error() method

Baseline 2026
Newly available

Since March 2026, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

Note: This feature is available in Web Workers.

The error() method of the ReadableByteStreamController interface causes any future interactions with the associated stream to error with the specified reason.

This is commonly called by an underlying source to surface an error from the interface where it gets its data (such as a file-read or socket error). It can also be called from elsewhere to trigger a stream error, for example if another part of the system that the stream relies on fails.

Syntax

js
error(errorObject)

Parameters

errorObject

Any object that you want future interactions to fail with.

Return value

None (undefined).

Exceptions

TypeError

Thrown if the source object is not a ReadableByteStreamController, or the stream is not readable for some other reason.

Examples

The example in Using readable byte streams > Creating a readable socket push byte stream shows how you might use error() to manually trigger a stream error if another part of the system it relies on fails.

Specifically, the underlying source start() method calls readRepeatedly() to perform all setup operations and to make a request for data. This returns a promise. If there are any errors thrown when reading the data they will be caught by the chained catch() function. In catch() we then call error() on the controller, passing the reason from the underlying source.

js
function start(controller) {
  readRepeatedly().catch((e) => controller.error(e));
}

function readRepeatedly() {
  return socket.select2().then(() => {
    // …
  });
}

Specifications

Specification
Streams
# ref-for-rbs-controller-error①

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
error
Chrome – Full support
Chrome 89 (Release date: 2021-03-02)
footnote Full support
Edge – Full support
Edge 89 (Release date: 2021-03-04)
footnote Full support
Firefox – Full support
Firefox 102 (Release date: 2022-06-28)
footnote Full support
Opera – Full support
Opera 75 (Release date: 2021-03-24)
footnote Full support
Safari – Full support
Safari 26.4 (Release date: 2026-03-24)
footnote Full support
Chrome Android – Full support
Chrome Android 89 (Release date: 2021-03-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 102 (Release date: 2022-06-28)
footnote Full support
Opera Android – Full support
Opera Android 63 (Release date: 2021-04-16)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.4 (Release date: 2026-03-24)
footnote Full support
Samsung Internet – Full support
Samsung Internet 15 (Release date: 2021-08-13)
footnote Full support
WebView Android – Full support
WebView Android 89 (Release date: 2021-03-02)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.4 (Release date: 2026-03-24)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 16.5 (Release date: 2021-07-14)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also