Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/error.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/streams/readablestreamdefaultcontroller/error/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
Menu
Documentation
Grafana k6
JavaScript API
k6/experimental
streams
ReadableStreamDefaultController
error(reason)
Open source
error(reason)
The error() method of the
ReadableStreamDefaultController makes any future interactions with the associated stream to error.
Parameters
| Name | Type | Description |
|---|---|---|
| e | any | The error to return to any future interactions with the stream. |
Exceptions
| Exception | Description |
|---|---|
| TypeError | Thrown when the source object is not a ReadableStreamDefaultController. |
Example
JavaScript
import { ReadableStream } from 'k6/experimental/streams';
import { setTimeout } from 'k6/timers';
export default async function () {
let currentNumber = 0;
const stream = new ReadableStream({
start(controller) {
const fn = () => {
if (currentNumber % 8 == 0) {
// Error the stream when the number is divisible by 8
controller.error('erroring the stream because we received a multiple of 8');
return;
}
if (currentNumber < 10) {
controller.enqueue(++currentNumber);
setTimeout(fn, 1000);
return;
}
controller.close();
};
setTimeout(fn, 1000);
},
});
const reader = stream.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(`received number ${value} from stream`);
}
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.
Choose a product
Viewing: v2.0.x (latest)
Find another version
Scroll for more