{"record":{"id":"d3543bcdafc92f16","repo":"oven-sh/bun","slug":"name-takes-three-arguments-but-got-name","errorCode":null,"errorMessage":"$$${name} takes three arguments, but got '$$${name}${inner.result}'","messagePattern":"\\$\\$(.+?) takes three arguments, but got '\\$\\$(.+?)(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/replacements.ts","lineNumber":258,"sourceCode":"        const str =\n          \"[\" +\n          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})`;","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/replacements.ts#L240-L276","documentation":"$newRustFunction/$newCppFunction create native function objects at bundle time and require exactly three literal arguments: (structName: string, functionName: string, length: number). The arity/type check runs after JSON parsing succeeds, so this error means the call parsed but did not match that shape.","triggerScenarios":"Calling $newRustFunction with two arguments (copying a $rust call site), passing the argument count as a string, or adding a trailing fourth argument.","commonSituations":"Copy-pasting a $rust(...) binding and just renaming the macro; updating a binding signature and forgetting the length parameter.","solutions":["Supply all three literals: $newRustFunction(\"MyStruct\", \"myFn\", 2).","Make the third argument a plain number literal (not \"2\" and not a variable).","If you only need an existing function, use $rust/$cpp (two string args) instead of the new* form."],"exampleFix":"// before\nconst fn = $newRustFunction(\"MyStruct\", \"myFn\");\n\n// after\nconst fn = $newRustFunction(\"MyStruct\", \"myFn\", 2);","handlingStrategy":"validation","validationCode":"const newFnRe = /\\$new(Rust|Cpp)Function\\((.*?)\\)/g;\nfor (const m of src.matchAll(newFnRe)) {\n  const args = m[2].split(\",\").map(s => s.trim());\n  const ok = args.length === 3 && /^(['\"]).*\\1$/.test(args[0]) && /^(['\"]).*\\1$/.test(args[1]) && /^\\d+$/.test(args[2]);\n  if (!ok) throw new Error(`bad $new${m[1]}Function call: ${m[0]}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the shapes: $newRustFunction/$newCppFunction(string, string, number); $rust/$cpp(string, string).","Prefer copy-pasting an existing correct call site and editing names only."],"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"}