different-ai/openwork · error · InterpreterRuntimeError
Generator functions are not supported in CodeMode.
Error message
Generator functions are not supported in CodeMode.
What it means
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.
Source
Thrown at packages/codemode/src/interpreter/runtime.ts:855
const result = yield* self.evaluateStatement(statement)
if (result.kind === "value") {
self.lastValue = result.value
continue
}
if (result.kind !== "none") {
return result
}
}
return { kind: "none" } satisfies StatementResult
}).pipe(Effect.ensuring(Effect.sync(() => self.popScope())))
}
private createFunction(node: AstNode): CodeModeFunction {
if (node.generator === true) {
throw new InterpreterRuntimeError(
"Generator functions are not supported in CodeMode.",
node,
"UnsupportedSyntax",
[supportedSyntaxMessage],
)
}
return new CodeModeFunction(
getArray(node, "params").map((parameter, index) => asNode(parameter, `params[${index}]`)),
getNode(node, "body"),
this.scopes.slice(),
)
}
// Function declarations are hoisted: bound in their scope before the body runs, so a
// program can call a helper defined further down (matching JavaScript).
private hoistFunctions(statements: Array<unknown>): void {
for (const statementValue of statements) {
if (!isRecord(statementValue) || statementValue.type !== "FunctionDeclaration") continueView on GitHub (pinned to 2b7df46e8a)
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
Example fix
// before
function* range(n) { for (let i = 0; i < n; i++) yield i; }
const vals = [...range(5)];
// after
function range(n) { const out = []; for (let i = 0; i < n; i++) out.push(i); return out; }
const vals = range(5); Defensive patterns
Strategy: validation
Validate before calling
if (/function\s*\*/.test(code) || /\byield\b/.test(code)) {
throw new Error('Generators (function*/yield) are unsupported in CodeMode; return arrays instead');
} Type guard
function usesGeneratorSyntax(code) { return /function\s*\*/.test(code) || /\byield\b/.test(code); } Prevention
- 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
When it happens
Trigger: Declaring function* gen() {...} or an async generator inside CodeMode code; createFunction is reached via hoistFunctions (top-level declarations) or evaluateExpression (function expressions, IIFEs).
Common situations: Porting iterator/generator-based utilities into sandboxed code; LLM-generated code that lazily produces sequences with generators; using yield for cooperative iteration patterns.
Related errors
- Array.from(...) does not support a map function in CodeMode;
- for await...of is not supported.
- Expected '${key}' to be a boolean.
- Failed to parse script as a Program node.
- String.${name} expects argument ${index + 1} to be a number.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/593e8516dbffd539.
Report an issue: GitHub.