Pumpkin-MC/Pumpkin · error
valid enchantment ID
Error message
valid enchantment ID
What it means
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.
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
Example fix
// before
Enchantment::from_id(id as u8).expect("valid enchantment ID")
// after
Enchantment::from_id(id as u8)
.unwrap_or_else(|| panic!("unknown WIT enchantment id {} (API version mismatch?)", id as u8)) Defensive patterns
Strategy: type-guard
Validate before calling
let id_num = id as u8;
if Enchantment::from_id(id_num).is_none() {
return Err(format!("unknown enchantment id {id_num}"));
} Type guard
fn is_known_enchantment(id: WitEnchantment) -> bool {
Enchantment::from_id(id as u8).is_some()
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- failed to add player resource
- failed to add player resource
- unexpected event type
- invalid text-component resource handle
- Cannot construct BlockFertilizeEvent from WASM
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/def77887e1c87ffe.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/item_stack.rs:49
pub(crate) fn to_wit_data_component(id: DataComponent) -> WitDataComponent {
// SAFETY: WIT enum is generated in the same order as the internal enum
unsafe { std::mem::transmute(id as u8) }
}
pub(crate) fn from_wit_data_component(id: WitDataComponent) -> DataComponent {
// SAFETY: WIT enum is generated in the same order as the internal enum
unsafe { std::mem::transmute(id as u8) }
}
pub(crate) fn to_wit_enchantment(id: &Enchantment) -> WitEnchantment {
// SAFETY: WIT enum is generated in the same order as the internal enum
unsafe { std::mem::transmute(id.id) }
}
pub(crate) fn from_wit_enchantment(id: WitEnchantment) -> &'static Enchantment {
// Safety: WIT enum is generated in the same order as the internal enum
Enchantment::from_id(id as u8).expect("valid enchantment ID")
}
#[must_use]
pub fn to_wit_attribute(attr: &Attributes) -> WitAttribute {
// SAFETY: WIT enum is generated in the same order as the internal ID
unsafe { std::mem::transmute(attr.id) }
}
#[must_use]
pub const fn from_wit_item_operation(op: WitModifierOperation) -> Operation {
match op {
WitModifierOperation::Add => Operation::AddValue,
WitModifierOperation::MultiplyBase => Operation::AddMultipliedBase,
WitModifierOperation::MultiplyTotal => Operation::AddMultipliedTotal,
}
}
#[must_use]View on GitHub (pinned to 8d4639e25a)