{"record":{"id":"593e8516dbffd539","repo":"different-ai/openwork","slug":"generator-functions-are-not-supported-in-codemode","errorCode":null,"errorMessage":"Generator functions are not supported in CodeMode.","messagePattern":"Generator functions are not supported in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":855,"sourceCode":"        const result = yield* self.evaluateStatement(statement)\n\n        if (result.kind === \"value\") {\n          self.lastValue = result.value\n          continue\n        }\n\n        if (result.kind !== \"none\") {\n          return result\n        }\n      }\n\n      return { kind: \"none\" } satisfies StatementResult\n    }).pipe(Effect.ensuring(Effect.sync(() => self.popScope())))\n  }\n\n  private createFunction(node: AstNode): CodeModeFunction {\n    if (node.generator === true) {\n      throw new InterpreterRuntimeError(\n        \"Generator functions are not supported in CodeMode.\",\n        node,\n        \"UnsupportedSyntax\",\n        [supportedSyntaxMessage],\n      )\n    }\n    return new CodeModeFunction(\n      getArray(node, \"params\").map((parameter, index) => asNode(parameter, `params[${index}]`)),\n      getNode(node, \"body\"),\n      this.scopes.slice(),\n    )\n  }\n\n  // Function declarations are hoisted: bound in their scope before the body runs, so a\n  // program can call a helper defined further down (matching JavaScript).\n  private hoistFunctions(statements: Array<unknown>): void {\n    for (const statementValue of statements) {\n      if (!isRecord(statementValue) || statementValue.type !== \"FunctionDeclaration\") continue","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L837-L873","documentation":"Generator functions (function* and yield) are not implemented in CodeMode. createFunction checks node.generator and throws an UnsupportedSyntax error before any code runs. The interpreter supports only ordinary function declarations/expressions and arrow functions.","triggerScenarios":"Declaring function* gen() {...} or an async generator inside CodeMode code; createFunction is reached via hoistFunctions (top-level declarations) or evaluateExpression (function expressions, IIFEs).","commonSituations":"Porting iterator/generator-based utilities into sandboxed code; LLM-generated code that lazily produces sequences with generators; using yield for cooperative iteration patterns.","solutions":["Rewrite the generator as a function returning a plain array of results","Replace lazy iteration with eager computation using loops","If the sequence is huge, process it in chunks with supported loop syntax or use a host tool"],"exampleFix":"// before\nfunction* range(n) { for (let i = 0; i < n; i++) yield i; }\nconst vals = [...range(5)];\n// after\nfunction range(n) { const out = []; for (let i = 0; i < n; i++) out.push(i); return out; }\nconst vals = range(5);","handlingStrategy":"validation","validationCode":"if (/function\\s*\\*/.test(code) || /\\byield\\b/.test(code)) {\n  throw new Error('Generators (function*/yield) are unsupported in CodeMode; return arrays instead');\n}","typeGuard":"function usesGeneratorSyntax(code) { return /function\\s*\\*/.test(code) || /\\byield\\b/.test(code); }","tryCatchPattern":null,"preventionTips":["Never declare function* or use yield in sandbox code","Return arrays from helper functions instead of generators","Add a pre-execution lint for generator syntax","Instruct code-generating models that generators are unsupported"],"tags":["codemode","generators","unsupported-syntax","functions"],"backgroundTag":"unsupported-api-in-sandbox","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}