{"record":{"id":"545a220faed41ed4","repo":"vercel/ai","slug":"aborterror-545a22","errorCode":"AbortError","errorMessage":"Stream aborted","messagePattern":"Stream aborted","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"info","filePath":"packages/svelte/src/structured-object.svelte.ts","lineNumber":188,"sourceCode":"\n      if (!response.ok) {\n        throw new Error(\n          (await response.text()) ?? 'Failed to fetch the response.',\n        );\n      }\n\n      if (response.body == null) {\n        throw new Error('The response body is empty.');\n      }\n\n      let accumulatedText = '';\n      let latestObject: DeepPartial<RESULT> | undefined = undefined;\n\n      await response.body.pipeThrough(new TextDecoderStream()).pipeTo(\n        new WritableStream<string>({\n          write: async chunk => {\n            if (abortController?.signal.aborted) {\n              throw new DOMException('Stream aborted', 'AbortError');\n            }\n            accumulatedText += chunk;\n\n            const { value } = await parsePartialJson(accumulatedText);\n            const currentObject = value as DeepPartial<RESULT>;\n\n            if (!isDeepEqualData(latestObject, currentObject)) {\n              latestObject = currentObject;\n\n              this.#store.object = currentObject;\n            }\n          },\n\n          close: async () => {\n            this.#store.loading = false;\n            this.#abortController = undefined;\n\n            if (this.#options.onFinish != null) {","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/svelte/src/structured-object.svelte.ts#L170-L206","documentation":"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.","triggerScenarios":"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.","commonSituations":"User navigates away or cancels generation; component unmount cleanup calls stop(); a timeout aborts the controller mid-stream. Usually expected behavior, not a bug.","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."],"exampleFix":"// before\nstartGeneration();\n// after\ntry {\n  startGeneration();\n} catch (error) {\n  if ((error as DOMException)?.name !== 'AbortError') throw error;\n}","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"function isAbortError(e) {\n  return e instanceof DOMException && e.name === 'AbortError';\n}","tryCatchPattern":"try {\n  await consumeStream();\n} catch (error) {\n  if (!isAbortError(error)) throw error; // ignore intentional stops\n}","preventionTips":["Never treat AbortError as a failure.","Only call stop() when cancellation is intended.","Clean up abort listeners on unmount.","Use generous AbortSignal timeouts."],"tags":["abort","streaming","svelte","cancellation"],"backgroundTag":"stream-aborted","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}