{"record":{"id":"6b2d86b60e4b8f24","repo":"oven-sh/bun","slug":"unknown-rust-file-identifier-json-stringify-f","errorCode":null,"errorMessage":"Unknown $rust() file identifier ${JSON.stringify(filename)}. Add it to rustIdentifierPaths in src/codegen/generate-js2native.ts.","messagePattern":"Unknown \\$rust\\(\\) file identifier (.+?)\\. Add it to rustIdentifierPaths in src/codegen/generate-js2native\\.ts\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-js2native.ts","lineNumber":117,"sourceCode":"  \"udp_socket.rs\": \"runtime/socket/udp_socket.rs\",\n  \"upgrade_command.rs\": \"runtime/cli/upgrade_command.rs\",\n  \"virtual_machine_exports.rs\": \"jsc/virtual_machine_exports.rs\",\n};\n\nfunction callBaseName(x: string) {\n  return x.split(/[^A-Za-z0-9]/g).pop()!;\n}\n\nfunction resolveNativeFileId(call_type: NativeCallType, filename: string) {\n  const ext = call_type === \"bind\" ? \".bind.ts\" : call_type === \"rust\" ? \".rs\" : `.${call_type}`;\n  if (!filename.endsWith(ext)) {\n    throw new Error(`Expected filename for $${call_type} to have ${ext} extension, got ${JSON.stringify(filename)}`);\n  }\n\n  if (call_type === \"rust\") {\n    const relative = rustIdentifierPaths[filename];\n    if (!relative) {\n      throw new Error(\n        `Unknown $rust() file identifier ${JSON.stringify(filename)}. Add it to rustIdentifierPaths in src/codegen/generate-js2native.ts.`,\n      );\n    }\n    return path.join(srcDir, relative.replaceAll(\"/\", sep));\n  }\n\n  filename = filename.replaceAll(\"/\", sep);\n\n  const resolved = sourceFiles.find(file => file.endsWith(sep + filename));\n  if (!resolved) {\n    const fnName = call_type === \"bind\" ? \"bindgenFn\" : call_type;\n    throw new Error(`Could not find file ${filename} in $${fnName} call`);\n  }\n\n  return filename;\n}\n\nexport function registerNativeCall(","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-js2native.ts#L99-L135","documentation":"For $rust() calls, generate-js2native.ts resolves .rs filenames through an explicit allowlist, rustIdentifierPaths, mapping known Rust file names to their paths under src/ (e.g. \"udp_socket.rs\" → \"runtime/socket/udp_socket.rs\"). Unlike other call types there is no filesystem search, so passing any .rs filename not in that map fails immediately with this error, which tells you to add it to the map.","triggerScenarios":"Writing $rust(\"my_new_module.rs\", \"BunMyApi\") in a .bind.ts file for a newly created Rust source file, without updating src/codegen/generate-js2native.ts.","commonSituations":"Contributors adding new Rust-backed JS APIs and hitting the codegen allowlist for the first time; moving a .rs file to a different directory so its old map entry no longer matches the new filename passed in.","solutions":["Open src/codegen/generate-js2native.ts and find the rustIdentifierPaths object near the top","Add an entry mapping your filename to its path relative to src/, e.g. \"my_new_module.rs\": \"runtime/api/my_new_module.rs\",","Re-run codegen — the error message itself confirms this is the intended fix"],"exampleFix":"// src/codegen/generate-js2native.ts\n// before\nconst rustIdentifierPaths = {\n  \"udp_socket.rs\": \"runtime/socket/udp_socket.rs\",\n};\n\n// after\nconst rustIdentifierPaths = {\n  \"udp_socket.rs\": \"runtime/socket/udp_socket.rs\",\n  \"my_new_module.rs\": \"runtime/api/my_new_module.rs\",\n};","handlingStrategy":"validation","validationCode":"// every $rust() filename must already be in the allowlist\nimport { rustIdentifierPaths } from \"./generate-js2native.ts\";\nfunction isKnownRustFile(filename: string): boolean {\n  return filename.endsWith(\".rs\") && Object.hasOwn(rustIdentifierPaths, filename);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adding a new Rust-backed binding is a two-step change: create the .rs file AND add its entry to rustIdentifierPaths in the same commit","When moving a .rs file, update both the map entry and any $rust() call sites that reference it"],"tags":["codegen","bindings","js2native","allowlist"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}