{"record":{"id":"7adc3760b26a594f","repo":"oven-sh/bun","slug":"unknown-wrap-kind-x-wrap-kind","errorCode":null,"errorMessage":"Unknown wrap kind ${x.wrap_kind}","messagePattern":"Unknown wrap kind (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-js2native.ts","lineNumber":238,"sourceCode":"              type: \"rust\",\n              symbol: x.symbol_target,\n              filename: x.filename,\n            })});`,\n          ),\n        \"\") || \"\",\n        `static ALWAYS_INLINE JSC::JSValue ${x.symbol_generated}(Zig::GlobalObject* globalObject) {`,\n        `  return JSC::JSFunction::create(globalObject->vm(), globalObject, ${x.call_length}, ${JSON.stringify(\n          x.display_name,\n        )}_s, ${symbol({\n          type: x.type,\n          symbol: x.symbol_target,\n\n          filename: x.filename,\n        })}, JSC::ImplementationVisibility::Public);`,\n        `}`,\n      ].join(\"\\n\");\n    }\n    throw new Error(`Unknown wrap kind ${x.wrap_kind}`);\n  });\n\n  return [\n    `#pragma once`,\n    `#include \"root.h\"`,\n    ...files.map(filename => `#include ${JSON.stringify(filename)}`),\n    ...externs,\n    \"\\n\" + \"namespace JS2NativeGenerated {\",\n    \"using namespace Bun;\",\n    \"using namespace JSC;\",\n    \"using namespace WebCore;\" + \"\\n\",\n    ...nativeCallStrings,\n    ...wrapperCallStrings,\n    ...nativeCalls\n      .filter(x => x.type === \"bind\")\n      .map(\n        x =>\n          `extern \"C\" SYSV_ABI JSC::EncodedJSValue js2native_bindgen_${basename(x.filename.replace(/\\.bind\\.ts$/, \"\"))}_${x.symbol}(Zig::GlobalObject*);`,","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-js2native.ts#L220-L256","documentation":"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.","triggerScenarios":"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.","commonSituations":"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\".","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// exhaustively narrow wrap_kind before emitting\nconst knownWrapKinds = [\"new-function\"] as const;\nfunction isKnownWrapKind(k: string): k is (typeof knownWrapKinds)[number] {\n  return (knownWrapKinds as readonly string[]).includes(k);\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["codegen","js2native","build-invariant","exhaustiveness"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}