vercel/ai · info · DOMException

Stream aborted

Error message

Stream aborted

What it means

StructuredObject aborts its underlying stream when the consumer calls `stop()`. The write handler checks `abortController.signal.aborted` on each chunk and throws an `AbortError` DOMException named 'Stream aborted' to unwind the pipe. It is an intentional cancellation signal, not a malfunction.

Source

Thrown at packages/angular/src/lib/structured-object.ng.ts:177

      if (!response.ok) {
        throw new Error(
          (await response.text()) ?? 'Failed to fetch the response.',
        );
      }

      if (response.body == null) {
        throw new Error('The response body is empty.');
      }

      let accumulatedText = '';
      let latestObject: DeepPartial<RESULT> | undefined = undefined;

      await response.body.pipeThrough(new TextDecoderStream()).pipeTo(
        new WritableStream<string>({
          write: async chunk => {
            if (abortController?.signal.aborted) {
              throw new DOMException('Stream aborted', 'AbortError');
            }
            accumulatedText += chunk;

            const { value } = await parsePartialJson(accumulatedText);
            const currentObject = value as DeepPartial<RESULT>;

            if (!isDeepEqualData(latestObject, currentObject)) {
              latestObject = currentObject;

              this.#object.set(currentObject);
            }
          },

          close: async () => {
            this.#loading.set(false);
            this.#abortController = undefined;

            if (this.options.onFinish != null) {

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Treat this as expected control flow: filter out/catch AbortError in your error handler for the object's error stream.
  2. Call `stop()` only when you intend to cancel, and stop listening for further updates.
  3. In cleanup code, guard so unmount-time aborts don't surface as user-facing errors.

Example fix

// before
object.error.subscribe(err => console.error(err));
// after
object.error.subscribe(err => {
  if (err instanceof DOMException && err.name === 'AbortError') return;
  console.error(err);
});
Defensive patterns

Strategy: try-catch

Validate before calling

null

Type guard

function isAbortError(e: unknown): e is DOMException {
  return e instanceof DOMException && e.name === 'AbortError';
}

Try / catch

try {
  await streamPipe;
} catch (e) {
  if (isAbortError(e)) return; // expected after stop()
  throw e;
}

Prevention

When it happens

Trigger: Calling the object instance's `stop()` method while the response stream is actively piping chunks, so the next `write()` in the WritableStream sees an aborted signal and throws.

Common situations: Component unmount/cleanup (NgOnDestroy) calling `stop()` mid-stream; user pressing a cancel button; route navigation while an object is still generating.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/0676cdff3a310c17. Report an issue: GitHub.