{"record":{"id":"def77887e1c87ffe","repo":"Pumpkin-MC/Pumpkin","slug":"valid-enchantment-id","errorCode":null,"errorMessage":"valid enchantment ID","messagePattern":"valid enchantment ID","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/item_stack.rs","lineNumber":49,"sourceCode":"\npub(crate) fn to_wit_data_component(id: DataComponent) -> WitDataComponent {\n    // SAFETY: WIT enum is generated in the same order as the internal enum\n    unsafe { std::mem::transmute(id as u8) }\n}\n\npub(crate) fn from_wit_data_component(id: WitDataComponent) -> DataComponent {\n    // SAFETY: WIT enum is generated in the same order as the internal enum\n    unsafe { std::mem::transmute(id as u8) }\n}\n\npub(crate) fn to_wit_enchantment(id: &Enchantment) -> WitEnchantment {\n    // SAFETY: WIT enum is generated in the same order as the internal enum\n    unsafe { std::mem::transmute(id.id) }\n}\n\npub(crate) fn from_wit_enchantment(id: WitEnchantment) -> &'static Enchantment {\n    // Safety: WIT enum is generated in the same order as the internal enum\n    Enchantment::from_id(id as u8).expect(\"valid enchantment ID\")\n}\n\n#[must_use]\npub fn to_wit_attribute(attr: &Attributes) -> WitAttribute {\n    // SAFETY: WIT enum is generated in the same order as the internal ID\n    unsafe { std::mem::transmute(attr.id) }\n}\n\n#[must_use]\npub const fn from_wit_item_operation(op: WitModifierOperation) -> Operation {\n    match op {\n        WitModifierOperation::Add => Operation::AddValue,\n        WitModifierOperation::MultiplyBase => Operation::AddMultipliedBase,\n        WitModifierOperation::MultiplyTotal => Operation::AddMultipliedTotal,\n    }\n}\n\n#[must_use]","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/item_stack.rs#L31-L67","documentation":"from_wit_enchantment converts a WIT enchantment enum value into the internal Enchantment type by calling Enchantment::from_id and expects the lookup to always succeed. The expect fires when the numeric ID carried by the WIT enchantment does not resolve to a known internal enchantment. Because the conversion relies on the WIT enum and internal enum being generated in the same order, this panic indicates enum drift between the plugin API surface and the server's enchantment registry.","triggerScenarios":"A plugin passes a WitEnchantment whose discriminant has no matching internal Enchantment ID — typically after the WIT enum gained a new variant the server's from_id table does not know, or a transmute/ordering mismatch shifts IDs; also reached via from_wasm_event, add_enchantment, and remove_enchantment calls.","commonSituations":"Version-skew between a compiled plugin binary (built against a newer/older WIT enum) and the running server; custom or modded enchantments registered server-side but absent from the plugin API enum.","solutions":["Verify plugin and server are built against the same pumpkin plugin API version and rebuild the plugin","Check that Enchantment::from_id covers every variant of the WIT enchantment enum; add missing mappings","Audit any code that transmutes raw IDs into WitEnchantment to ensure the value is within the valid enum range","Log the offending id value and add a bounds check before conversion instead of relying on expect"],"exampleFix":"// before\n    Enchantment::from_id(id as u8).expect(\"valid enchantment ID\")\n// after\n    Enchantment::from_id(id as u8)\n        .unwrap_or_else(|| panic!(\"unknown WIT enchantment id {} (API version mismatch?)\", id as u8))","handlingStrategy":"type-guard","validationCode":"let id_num = id as u8;\nif Enchantment::from_id(id_num).is_none() {\n    return Err(format!(\"unknown enchantment id {id_num}\"));\n}","typeGuard":"fn is_known_enchantment(id: WitEnchantment) -> bool {\n    Enchantment::from_id(id as u8).is_some()\n}","tryCatchPattern":null,"preventionTips":["Always build plugins against the same pumpkin API version as the server","Never transmute raw integers into enum types without a range check","Add a test asserting WIT enum variants == internal enum variants count/order","Prefer returning Result over expect at API boundaries"],"tags":["wasm","plugin-api","panic","enchantment"],"backgroundTag":"invalid-enum-value","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}