{"record":{"id":"30569f293c4c89a0","repo":"different-ai/openwork","slug":"console-ref-name-is-not-available-in-codemode","errorCode":null,"errorMessage":"console.${ref.name} is not available in CodeMode.","messagePattern":"console\\.(.+?) is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":553,"sourceCode":"      if (typeof source === \"string\") return Array.from(source)\n      if (Array.isArray(source)) return [...source]\n      if (\n        source !== null &&\n        typeof source === \"object\" &&\n        typeof (source as { length?: unknown }).length === \"number\"\n      ) {\n        return Array.from(source as ArrayLike<unknown>)\n      }\n      throw new InterpreterRuntimeError(\"Array.from expects an array, string, Map, Set, or array-like value.\", node)\n    }\n    default:\n      throw new InterpreterRuntimeError(`Array.${name} is not available in CodeMode.`, node)\n  }\n}\n\nconst invokeGlobalMethod = (ref: GlobalMethodReference, args: Array<unknown>, node: AstNode): unknown => {\n  if (ref.namespace === \"console\")\n    throw new InterpreterRuntimeError(`console.${ref.name} is not available in CodeMode.`, node)\n  if (ref.namespace === \"Object\") return invokeObjectMethod(ref.name, args, node)\n  if (ref.namespace === \"Math\") return invokeMathMethod(ref.name, args, node)\n  if (ref.namespace === \"Array\") return invokeArrayStatic(ref.name, args, node)\n  if (ref.namespace === \"Number\") return invokeNumberStatic(ref.name, args, node)\n  if (ref.namespace === \"String\") return invokeStringStatic(ref.name, args, node)\n  if (ref.namespace === \"URL\") return invokeURLStatic(ref.name, args, node)\n  if (ref.namespace === \"Date\") {\n    if (!dateStatics.has(ref.name))\n      throw new InterpreterRuntimeError(`Date.${ref.name} is not available in CodeMode.`, node)\n    return invokeDateStatic(ref.name, args, node)\n  }\n  if (\n    ref.namespace === \"RegExp\" ||\n    ref.namespace === \"Map\" ||\n    ref.namespace === \"Set\" ||\n    ref.namespace === \"URLSearchParams\"\n  ) {\n    throw new InterpreterRuntimeError(`${ref.namespace}.${ref.name} is not available in CodeMode.`, node)","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L535-L571","documentation":"console.* methods (log, error, warn, etc.) are not implemented in CodeMode at all. invokeGlobalMethod rejects any reference whose namespace is 'console' before dispatching to other namespaces. The sandbox has no I/O console, so all console access is an immediate error.","triggerScenarios":"Any console.log(...), console.error(...), console.warn(...), console.table(...) etc. inside CodeMode code, dispatched via invokeGlobalMethod from evaluateCallExpression.","commonSituations":"Debugging habits carried over from normal JS; LLM-generated code that logs progress; porting scripts that rely on console output for results.","solutions":["Remove console.* calls and return the value instead (return data from the code)","Collect messages into an array/string variable and return it for inspection","Use the host environment's tooling/observability rather than in-code logging"],"exampleFix":"// before\nconsole.log('result:', data);\nreturn data;\n// after\nreturn data; // inspect the returned value","handlingStrategy":"validation","validationCode":"if (/\\bconsole\\s*\\./.test(code)) {\n  throw new Error('console.* is unavailable in CodeMode; return values instead of logging');\n}","typeGuard":null,"tryCatchPattern":"try {\n  result = invokeCodeMode(code);\n} catch (e) {\n  if (String(e.message).includes('console.')) {\n    // strip logging and re-run, or instruct the model to return values\n  } else throw e;\n}","preventionTips":["Never use console.log in sandbox code; return data instead","Accumulate diagnostics in an array and return it","Add a lint/strip step for console.* before execution","Instruct code-generating models that console is unavailable"],"tags":["codemode","sandbox","console","unsupported-api"],"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"}