{"record":{"id":"680638f04a3dc222","repo":"different-ai/openwork","slug":"url-method-name-is-not-available-in-codemode","errorCode":null,"errorMessage":"URL method '${name}' is not available in CodeMode.","messagePattern":"URL method '(.+?)' is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/url.ts","lineNumber":86,"sourceCode":"export const urlArgument = (value: unknown, label: string): string =>\n  value instanceof SandboxURL ? value.url.href : uriArgument(value, label)\n\nexport const invokeURLStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  if (!urlStatics.has(name)) throw new InterpreterRuntimeError(`URL.${name} is not available in CodeMode.`, node)\n  if (args.length === 0) throw new InterpreterRuntimeError(`URL.${name} requires a URL argument.`, node).as(\"TypeError\")\n  const input = urlArgument(args[0], `URL.${name} input`)\n  const base = args[1] === undefined ? undefined : urlArgument(args[1], `URL.${name} base`)\n  try {\n    const url = new URL(input, base)\n    return name === \"canParse\" ? true : new SandboxURL(url)\n  } catch {\n    return name === \"canParse\" ? false : null\n  }\n}\n\nexport const invokeURLMethod = (value: SandboxURL, name: string, node: AstNode): string => {\n  if (name === \"toString\" || name === \"toJSON\") return value.url.href\n  throw new InterpreterRuntimeError(`URL method '${name}' is not available in CodeMode.`, node)\n}\nimport { type AstNode, InterpreterRuntimeError, UriFunction } from \"../interpreter/model.js\"\nimport { SandboxURL } from \"../values.js\"\nimport { boundedData, coerceToString } from \"./value.js\"\n","sourceCodeStart":68,"sourceCodeEnd":91,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/url.ts#L68-L91","documentation":"Sandbox URL instance values support only toString and toJSON. Any other method call on a SandboxURL (e.g. url.hostname getters are fine as properties, but method invocations outside the whitelist) is rejected to keep the sandbox API minimal.","triggerScenarios":"Calling `url.someMethod()` on a SandboxURL where someMethod is not toString/toJSON — for example emulating WHATWG URL instance APIs from regular JS.","commonSituations":"Porting Node/browser URL-handling code into CodeMode that relies on full URL instance methods.","solutions":["Use toString() or toJSON() to get the href string, then operate on the string.","Access URL properties (href, host, pathname, etc.) directly instead of calling methods.","Parse the href back with URL statics exposed by the sandbox if restructuring is needed."],"exampleFix":"// before\nconst host = url.someHostMethod()\n// after\nconst host = new URL(url.toJSON()).host","handlingStrategy":"validation","validationCode":"if (typeof url.toString !== \"function\" || ![\"toString\",\"toJSON\"].includes(methodName)) throw new TypeError(\"only toString/toJSON available on sandbox URL\")","typeGuard":"const isAllowedURLMethod = (name) => name === \"toString\" || name === \"toJSON\"","tryCatchPattern":"try { s = url.fancyMethod() } catch { s = url.toJSON() }","preventionTips":["Treat SandboxURL as a value with href, not a full WHATWG URL","Convert to string early and parse fields from it","Consult sandbox docs before porting URL code"],"tags":["codemode","url","sandbox","unsupported-api"],"backgroundTag":"api-not-available-in-sandbox","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}