{"record":{"id":"729863b6e96f468b","repo":"different-ai/openwork","slug":"for-await-of-is-not-supported","errorCode":null,"errorMessage":"for await...of is not supported.","messagePattern":"for await\\.\\.\\.of is not supported\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":1076,"sourceCode":"          }\n        }\n\n        if (updateNode) {\n          yield* self.evaluateExpression(updateNode)\n        }\n\n        if (result.kind === \"continue\") {\n          continue\n        }\n      }\n\n      return { kind: \"none\" } satisfies StatementResult\n    }).pipe(Effect.ensuring(Effect.sync(() => self.popScope())))\n  }\n\n  private evaluateForOfStatement(node: AstNode): Effect.Effect<StatementResult, unknown, R> {\n    if (getBoolean(node, \"await\")) {\n      throw new InterpreterRuntimeError(\"for await...of is not supported.\", node)\n    }\n\n    const self = this\n    return Effect.gen(function* () {\n      const left = getNode(node, \"left\")\n      const right = yield* self.evaluateExpression(getNode(node, \"right\"))\n      const body = getNode(node, \"body\")\n\n      // Arrays iterate in place; strings iterate code points; Maps iterate [key, value]\n      // pairs and Sets iterate values over a snapshot (mutation during iteration is safe).\n      const iterable = Array.isArray(right) ? right : spreadItems(right)\n      if (iterable === undefined) {\n        throw new InterpreterRuntimeError(\"for...of requires an array, string, Map, or Set value in CodeMode.\", node)\n      }\n\n      let declaration: { readonly pattern: AstNode; readonly mutable: boolean } | undefined\n      let assignmentName: string | undefined\n","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L1058-L1094","documentation":"The CodeMode interpreter does not implement the async-iteration form of for...of. evaluateForOfStatement checks the parsed `await` flag on the for...of node and throws immediately before evaluating anything. Async iteration (async generators/streams) is outside the sandbox's supported surface.","triggerScenarios":"Writing `for await (const x of asyncIterable)` in CodeMode source — e.g. iterating an async generator or an async stream.","commonSituations":"Porting plain JavaScript that consumes async generators or streams into CodeMode scripts; the dialect simply has no async iteration support.","solutions":["Rewrite the loop to consume a synchronous array: collect results first (via an awaited tool call returning an array), then `for (const x of results)`.","Use `.then`-free patterns: have the tool API return a full data array instead of an async iterable.","If async iteration is essential, run the code outside CodeMode (plain JS execution environment)."],"exampleFix":"// before\nfor await (const chunk of stream) { ... }\n// after\nconst chunks = await readAll(streamTool)\nfor (const chunk of chunks) { ... }","handlingStrategy":"validation","validationCode":"// reject for-await before handing code to CodeMode\nif (/for\\s+await\\s*\\(/.test(source)) {\n  throw new Error(\"CodeMode does not support for await...of; collect results into an array first\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  await interpret(src);\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && e.message.includes(\"for await\")) {\n    // fall back to a tool call that returns a complete array\n  }\n  throw e;\n}","preventionTips":["Never write for await in CodeMode scripts.","Have tools return full arrays instead of async iterables.","Lint generated CodeMode code for `for await` before execution."],"tags":["codemode","interpreter","async-iteration","unsupported-syntax"],"backgroundTag":"unsupported-async-iteration","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}