vercel/ai · info · DOMException
AbortError
AbortError
Error message
Stream aborted
What it means
While piping the streamed response into the accumulated-text parser, the write handler checks abortController.signal.aborted and throws a DOMException('Stream aborted', 'AbortError') to stop processing. This is the deliberate stop mechanism: calling stop() on the structured object aborts the in-flight stream.
Source
Thrown at packages/svelte/src/structured-object.svelte.ts:188
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.#store.object = currentObject;
}
},
close: async () => {
this.#store.loading = false;
this.#abortController = undefined;
if (this.#options.onFinish != null) {View on GitHub (pinned to 69428b1f8b)
Solutions
- Treat AbortError as an intentional stop — catch and ignore it in your error handling.
- If it fires unexpectedly, check for early unmount or premature stop() calls.
- Use an AbortSignal timeout that is long enough for generation to complete.
- Handle the latestObject already accumulated if partial results are useful.
Example fix
// before
startGeneration();
// after
try {
startGeneration();
} catch (error) {
if ((error as DOMException)?.name !== 'AbortError') throw error;
} Defensive patterns
Strategy: type-guard
Validate before calling
null
Type guard
function isAbortError(e) {
return e instanceof DOMException && e.name === 'AbortError';
} Try / catch
try {
await consumeStream();
} catch (error) {
if (!isAbortError(error)) throw error; // ignore intentional stops
} Prevention
- Never treat AbortError as a failure.
- Only call stop() when cancellation is intended.
- Clean up abort listeners on unmount.
- Use generous AbortSignal timeouts.
When it happens
Trigger: Calling the stop() function returned by useStructuredObject while the response stream is still being consumed; the internal AbortController is aborted and the next write chunk raises this AbortError.
Common situations: User navigates away or cancels generation; component unmount cleanup calls stop(); a timeout aborts the controller mid-stream. Usually expected behavior, not a bug.
Related errors
- Stream aborted
- Transcription request was aborted
- AbortError
- MCP client initialization was aborted
- Failed to fetch the response.
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/545a220faed41ed4.
Report an issue: GitHub.