Pumpkin-MC/Pumpkin · error
unexpected event
Error message
unexpected event
What it means
This panic fires in `data_from_event`, the `Event` trait implementation for `CraftItemEvent`. It matches only `Event::CraftItemEvent(data)`; any other `Event` variant means the dispatcher handed a wrong-type payload to the crafting handler. The library considers this a broken internal invariant and panics with "unexpected event".
Solutions
- Register the handler with `EventType::CraftItemEvent` and verify the dispatch route sends only that variant.
- When calling manually, wrap data with `CraftItemEvent::data_into_event(data)` first.
- Keep pumpkin-plugin-api versions identical across crates and rebuild from clean.
- Pre-narrow with `if let Event::CraftItemEvent(data) = event { ... }`.
- Return `Option`/`Result` and log instead of panicking.
Example fix
// before
match event {
Event::CraftItemEvent(data) => data,
_ => panic!("unexpected event"),
}
// after
match event {
Event::CraftItemEvent(data) => data,
_ => log::warn!("CraftItemEvent handler got wrong event"),
_ => return None,
} Defensive patterns
Strategy: type-guard
Validate before calling
// Before dispatch assert_eq!(event.event_type(), EventType::CraftItemEvent, "wrong event routed to CraftItem handler");
Type guard
fn as_craft_item(event: &Event) -> Option<&CraftItemEventData> {
match event {
Event::CraftItemEvent(data) => Some(data),
_ => None,
}
} Try / catch
let result = std::panic::catch_unwind(AssertUnwindSafe(|| handler.data_from_event(event)));
if result.is_err() {
log::error!("CraftItemEvent handler received an unexpected event variant");
} Prevention
- Register the handler with EventType::CraftItemEvent.
- Use if-let narrowing instead of blind data_from_event calls.
- Always wrap payload data with the type's data_into_event when producing Event values.
- Pin identical pumpkin-plugin-api versions across the workspace.
- Add a debug_assert in dispatch code comparing event.event_type() to the handler's EVENT_TYPE.
When it happens
Trigger: Dispatching a non-`CraftItemEvent` variant (e.g. `FurnaceExtractEvent`) into `data_from_event`, or registering this handler under a `EventType` other than `CraftItemEvent`.
Common situations: Mismatched handler registration tables, hand-written dispatch where inventory events are conflated, or an upgrade that changed the `Event` enum so the handler's match arm no longer aligns with what's dispatched.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/932f7500f6d65f9e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-plugin-api/src/events/inventory/craft_item.rs:13
use super::super::FromIntoEvent;
use crate::wit::pumpkin::plugin::event::{CraftItemEventData, Event, EventType};
/// Event triggered when an item is crafted.
pub struct CraftItemEvent;
impl FromIntoEvent for CraftItemEvent {
const EVENT_TYPE: EventType = EventType::CraftItemEvent;
type Data = CraftItemEventData;
fn data_from_event(event: Event) -> Self::Data {
match event {
Event::CraftItemEvent(data) => data,
_ => panic!("unexpected event"),
}
}
fn data_into_event(data: Self::Data) -> Event {
Event::CraftItemEvent(data)
}
}
View on GitHub (pinned to 8d4639e25a)