{"record":{"id":"f9e987bb60083c1e","repo":"oven-sh/bun","slug":"call-is-not-known-at-bundle-time-name-inne","errorCode":null,"errorMessage":"Call is not known at bundle-time: '$$${name}${inner.result}'","messagePattern":"Call is not known at bundle-time: '\\$\\$(.+?)(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/replacements.ts","lineNumber":249,"sourceCode":"        true,\n      ];\n    } else if ([\"rust\", \"cpp\", \"newRustFunction\", \"newCppFunction\"].includes(name)) {\n      const kind = name.includes(\"ust\") ? \"rust\" : \"cpp\";\n      const is_create_fn = name.startsWith(\"new\");\n\n      const inner = sliceSourceCode(rest, true);\n      let args;\n      try {\n        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\") {","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/replacements.ts#L231-L267","documentation":"The builtin-module preprocessor evaluates $rust/$cpp/$newRustFunction/$newCppFunction calls at bundle time: it slices out the argument text, converts single quotes to double quotes, and JSON.parses it. These macros register native FFI functions and must take literal arguments; if the slice is not parseable JSON (template literals, variables, escapes that break quoting), the call is not statically known and codegen throws.","triggerScenarios":"Calling $rust(...) / $cpp(...) / $newRustFunction(...) inside src/js with anything except plain string/number literals — e.g. `const n = \"Bun\"; $rust(n, \"open\")`, backtick strings, or strings containing unescaped double quotes.","commonSituations":"Refactoring builtin code to hoist the struct/function names into constants; adding a new $rust binding and pasting a template-literal call site.","solutions":["Inline the arguments as literals: $rust(\"StructName\", \"functionName\").","Use single-quoted or plain double-quoted strings without internal double quotes; escape any nested quotes as \\\".","Do not wrap macro arguments in template literals or pass variables — the bundler cannot evaluate them."],"exampleFix":"// before\nconst s = \"BunObject\";\nconst fn = $rust(s, \"open\");\n\n// after\nconst fn = $rust(\"BunObject\", \"open\");","handlingStrategy":"validation","validationCode":"const macroCallRe = /\\$\\w+\\s*\\(/g;\nconst literalArgsRe = /^\\$\\w+\\(\\s*(['\"][^'\"]*['\"]\\s*(,\\s*['\"][^'\"]*['\"]\\s*)*)?\\)$/;\nfor (const line of builtinSource.split(\"\\n\")) {\n  if (macroCallRe.test(line) && !literalArgsRe.test(line.trim())) {\n    console.warn(`check macro call uses only literal args: ${line.trim()}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat $rust/$cpp/$new*/$bindgenFn arguments as data, not code: literals only, never variables or template literals.","Avoid double quotes inside argument strings; the preprocessor swaps single quotes to double and JSON.parses.","Centralize bindings in one file so a review of that file covers all macro call sites."],"tags":["codegen","macro-preprocessor","ffi","builtin-bundler"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}