{"record":{"id":"0bad0ba3b9c2702f","repo":"sveltejs/kit","slug":"query-live-name-must-return-an-iterator-iter","errorCode":null,"errorMessage":"query.live '${name}' must return an Iterator, Iterable, AsyncIterator or AsyncIterable","messagePattern":"query\\.live '(.+?)' must return an Iterator, Iterable, AsyncIterator or AsyncIterable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/app/server/remote/shared.js","lineNumber":216,"sourceCode":" * @param {Awaited<RemoteLiveQueryUserFunctionReturnType<T>>} source\n * @param {string} name\n * @returns {Iterator<T> | AsyncIterator<T>}\n */\nfunction to_iterator(source, name) {\n\t// intentionally using `in` because these could be inherited\n\tif ('next' in source && typeof source.next === 'function') {\n\t\treturn source;\n\t}\n\n\tif (Symbol.asyncIterator in source && typeof source[Symbol.asyncIterator] === 'function') {\n\t\treturn source[Symbol.asyncIterator]();\n\t}\n\n\tif (Symbol.iterator in source && typeof source[Symbol.iterator] === 'function') {\n\t\treturn source[Symbol.iterator]();\n\t}\n\n\tthrow new Error(\n\t\t`query.live '${name}' must return an Iterator, Iterable, AsyncIterator or AsyncIterable`\n\t);\n}\n\n/**\n * Note that `state` is deliberately not optional: resources that capture the request\n * state at creation must pass it explicitly, because reading it from the request store\n * at call time is only equivalent on runtimes with `AsyncLocalStorage` support.\n * Callers without a captured state (such as the module-level `form` instance getters)\n * should pass `get_request_store().state` themselves.\n * @param {RemoteInternals} internals\n * @param {RequestState} state\n */\nexport function get_cache(internals, state) {\n\tlet cache = state.remote.data?.get(internals);\n\n\tif (cache === undefined) {\n\t\tcache = {};","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/app/server/remote/shared.js#L198-L234","documentation":"`query.live` returns a live stream of values, so the query function must return something iterable: a sync/async Iterator or Iterable (e.g. an async generator, array of promises, ReadableStream-like object). If the returned value supports none of `Symbol.asyncIterator`/`Symbol.iterator` protocols, `to_iterator` throws this error. Return an (async) generator or iterable from the `query.live` function.","triggerScenarios":"A `query.live` function whose return value is a plain object, a Promise of a non-iterable, `undefined`, a number/string-wrapped value without iterator protocol, or a plain single value instead of a stream.","commonSituations":"Returning the result of `db.query()` (a plain Promise resolving to one row) instead of a cursor/stream; forgetting `async function*` and using `async function`; returning an object map instead of an array.","solutions":["Make the query function an async generator: `query.live(async function* () { yield* stream; })`","Return an async iterable source (e.g. an event emitter wrapped with an async generator, or an array)","If only one value is needed, use plain `query` instead of `query.live`"],"exampleFix":"// before\nexport const ticks = query.live(() => Date.now());\n// after\nexport const ticks = query.live(async function* () {\n  while (true) {\n    yield Date.now();\n    await new Promise((r) => setTimeout(r, 1000));\n  }\n});","handlingStrategy":"validation","validationCode":"function assertAsyncIterable(value) {\n  if (value == null || !(Symbol.asyncIterator in Object(value)) && !(Symbol.iterator in Object(value))) {\n    throw new TypeError('query.live function must return an (async) iterable');\n  }\n  return value;\n}","typeGuard":"const isIterable = (v) => v != null && (typeof v[Symbol.asyncIterator] === 'function' || typeof v[Symbol.iterator] === 'function');","tryCatchPattern":"try {\n  const iter = to_iterator(result);\n} catch (e) {\n  if (e.message.includes('must return an Iterator')) {\n    console.error('Wrap the single value in an async generator before returning');\n  }\n  throw e;\n}","preventionTips":["Always implement query.live bodies as `async function*` generators","Unit-test that the query returns an async iterable before shipping","Use plain `query` when only a single value is produced"],"tags":["remote-functions","query-live","async-iterator"],"backgroundTag":"not-iterable-return","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}