oven-sh/bun · error · Error
Unknown wrap kind ${x.wrap_kind}
Error message
Unknown wrap kind ${x.wrap_kind} What it means
While emitting the JS2Native C++ header, generate-js2native.ts dispatches on each registered call's wrap_kind; today the only implemented kind is "new-function" (emit a JSC::JSFunction::create wrapper). This throw is the exhaustive-match guard: it can only fire if the wrap_kind data structure gains a new value whose emitting branch was never added — i.e. a generator-internal invariant break, not a user configuration error.
Source
Thrown at src/codegen/generate-js2native.ts:238
type: "rust",
symbol: x.symbol_target,
filename: x.filename,
})});`,
),
"") || "",
`static ALWAYS_INLINE JSC::JSValue ${x.symbol_generated}(Zig::GlobalObject* globalObject) {`,
` return JSC::JSFunction::create(globalObject->vm(), globalObject, ${x.call_length}, ${JSON.stringify(
x.display_name,
)}_s, ${symbol({
type: x.type,
symbol: x.symbol_target,
filename: x.filename,
})}, JSC::ImplementationVisibility::Public);`,
`}`,
].join("\n");
}
throw new Error(`Unknown wrap kind ${x.wrap_kind}`);
});
return [
`#pragma once`,
`#include "root.h"`,
...files.map(filename => `#include ${JSON.stringify(filename)}`),
...externs,
"\n" + "namespace JS2NativeGenerated {",
"using namespace Bun;",
"using namespace JSC;",
"using namespace WebCore;" + "\n",
...nativeCallStrings,
...wrapperCallStrings,
...nativeCalls
.filter(x => x.type === "bind")
.map(
x =>
`extern "C" SYSV_ABI JSC::EncodedJSValue js2native_bindgen_${basename(x.filename.replace(/\.bind\.ts$/, ""))}_${x.symbol}(Zig::GlobalObject*);`,View on GitHub (pinned to 8c5296ac45)
Solutions
- Find where the unexpected wrap_kind value is produced (registration at line ~166 or the type at line ~20) and either fix it to "new-function" or implement the new kind
- Add the matching `if (x.wrap_kind === "...")` branch before the final throw in the emit function
- Keep the throw as the exhaustiveness guard — do not silence it with a default branch
Defensive patterns
Strategy: type-guard
Type guard
// exhaustively narrow wrap_kind before emitting
const knownWrapKinds = ["new-function"] as const;
function isKnownWrapKind(k: string): k is (typeof knownWrapKinds)[number] {
return (knownWrapKinds as readonly string[]).includes(k);
} Prevention
- This guard only fires when modifying the generator itself — always pair a new wrap_kind value with its emit branch in the same change
- Keep the final throw as the exhaustiveness check; a silent default branch would emit a broken header
When it happens
Trigger: Extending generate-js2native.ts (or its input producers) with a new wrap_kind value while only adding it to the type/registration side, leaving the emit switch at line 215 unhandled.
Common situations: Almost exclusively hit by developers modifying the codegen itself; never by .classes.ts or .bind.ts authors, since no external input can supply a wrap_kind other than "new-function".
Related errors
- Missing output for ${id}
- Expected filename for $${call_type} to have ${ext} extension
- Unknown $rust() file identifier ${JSON.stringify(filename)}.
- Could not find file ${filename} in $${fnName} call
- file did not exist after write: ${outputPath}
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/7adc3760b26a594f.
Report an issue: GitHub.