{"record":{"id":"0119f32627d2a50d","repo":"oven-sh/bun","slug":"name-takes-two-string-arguments-but-got","errorCode":null,"errorMessage":"$$${name} takes two string arguments, but got '$$${name}${inner.result}'","messagePattern":"\\$\\$(.+?) takes two string arguments, but got '\\$\\$(.+?)(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/replacements.ts","lineNumber":260,"sourceCode":"          inner.result\n            .slice(1, -1)\n            .replaceAll(\"'\", '\"')\n            .replace(/,[\\s\\n]*$/s, \"\") +\n          \"]\";\n        args = JSON.parse(str);\n      } catch {\n        throw new Error(`Call is not known at bundle-time: '$${name}${inner.result}'`);\n      }\n      if (\n        args.length != (is_create_fn ? 3 : 2) ||\n        typeof args[0] !== \"string\" ||\n        typeof args[1] !== \"string\" ||\n        (is_create_fn && typeof args[2] !== \"number\")\n      ) {\n        if (is_create_fn) {\n          throw new Error(`$${name} takes three arguments, but got '$${name}${inner.result}'`);\n        } else {\n          throw new Error(`$${name} takes two string arguments, but got '$${name}${inner.result}'`);\n        }\n      }\n\n      const id = registerNativeCall(kind, args[0], args[1], is_create_fn ? args[2] : null);\n\n      return [slice.slice(0, match.index) + \"__intrinsic__lazy(\" + id + \")\", inner.rest, true];\n    } else if (name === \"isPromiseFulfilled\" || name === \"isPromiseRejected\" || name === \"isPromisePending\") {\n      const inner = sliceSourceCode(rest, true);\n      // JSC::JSPromise::Status: Pending = 0, Fulfilled = 1, Rejected = 2.\n      const status = name === \"isPromisePending\" ? 0 : name === \"isPromiseFulfilled\" ? 1 : 2;\n      let args;\n      if (debug) {\n        // use a property on @lazy as a temporary holder for the expression. only in debug!\n        args = `($assert(__intrinsic__isPromise(__intrinsic__lazy.temp=${inner.result.slice(0, -1)}))),__intrinsic__peekPromiseStatus(__intrinsic__lazy.temp) === (__intrinsic__lazy.temp = undefined, ${status}))`;\n      } else {\n        args = `(__intrinsic__peekPromiseStatus${inner.result} === ${status})`;\n      }\n      return [slice.slice(0, match.index) + args, inner.rest, true];","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/replacements.ts#L242-L278","documentation":"$rust(struct, fn) and $cpp(struct, fn) lazily bind an existing native function at bundle time and require exactly two string literal arguments. This error fires when the argument list parsed successfully but the shape is wrong — wrong count, non-string arguments, or a number in a string slot.","triggerScenarios":"Calling $rust(\"Struct\") with one argument, passing a number as one of the names, or copying a $newRustFunction three-arg call into a $rust site.","commonSituations":"Switching between $rust and $newRustFunction forms while editing builtin FFI bindings; accidentally deleting one argument.","solutions":["Pass exactly two string literals: $rust(\"StructName\", \"functionName\").","Use $newRustFunction/$newCppFunction if the binding needs a third length argument.","Check for a stray trailing comma or removed argument after edits."],"exampleFix":"// before\nconst fn = $rust(\"MyStruct\");\n\n// after\nconst fn = $rust(\"MyStruct\", \"myFn\");","handlingStrategy":"validation","validationCode":"const rustRe = /\\$(rust|cpp)\\((.*?)\\)/g;\nfor (const m of src.matchAll(rustRe)) {\n  const args = m[2].split(\",\").map(s => s.trim());\n  if (args.length !== 2 || !args.every(a => /^(['\"]).*\\1$/.test(a))) {\n    throw new Error(`$${m[1]} needs exactly two string literals: ${m[0]}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["After editing a binding line, recount arguments — the two-arg form is easy to truncate.","Keep $rust and $newRustFunction call sites visually distinct (one line each)."],"tags":["codegen","macro-preprocessor","ffi","arguments"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}