{"record":{"id":"8fa46f5f2e5ff745","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-8fa46f","errorCode":null,"errorMessage":"unexpected event","messagePattern":"unexpected event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-plugin-api/src/events/entity/entity_drop_item.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntityDropItemEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when an entity drops an item.\npub struct EntityDropItemEvent;\nimpl FromIntoEvent for EntityDropItemEvent {\n    const EVENT_TYPE: EventType = EventType::EntityDropItemEvent;\n    type Data = EntityDropItemEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntityDropItemEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntityDropItemEvent(data)\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-plugin-api/src/events/entity/entity_drop_item.rs#L1-L22","documentation":"This panic fires inside `data_from_event` for EntityDropItemEvent when the incoming `Event` is not `Event::EntityDropItemEvent`. The function unwraps the generic `Event` enum into `EntityDropItemEventData`, and the catch-all panics on any other variant since the dispatcher contract guarantees a match. It indicates the event was misrouted or manually constructed with the wrong variant.","triggerScenarios":"Passing a non-`EntityDropItemEvent` variant into `data_from_event` — manual dispatch with the wrong variant, a dispatcher bug pairing `EventType::EntityDropItemEvent` with foreign data, or test code that feeds unrelated events through this implementation.","commonSituations":"Copy-paste mistakes in custom dispatch/test harnesses; plugin registries that forward raw `Event` values without checking the declared `EventType`; mixed plugin-api versions causing variant mismatch.","solutions":["Route the event as `Event::EntityDropItemEvent(data)` before calling `data_from_event`","Check `EVENT_TYPE`/`event_type()` before forwarding an `Event` through a handler","Keep plugin-api and host versions in sync so `Event` variants correspond","Handle the mismatch arm gracefully (log and skip) instead of panicking in production paths"],"exampleFix":"// before\n<EntityDropItemEvent as Event>::data_from_event(Event::EntityDyeEvent(dye_data));\n// after\n<EntityDropItemEvent as Event>::data_from_event(Event::EntityDropItemEvent(drop_data));","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::EntityDropItemEvent(_)) { return; }\n<crate::events::entity::entity_drop_item::EntityDropItemEvent as Event>::data_from_event(event);","typeGuard":"fn as_entity_drop_item(event: &Event) -> Option<&EntityDropItemEventData> {\n    match event { Event::EntityDropItemEvent(d) => Some(d), _ => None }\n}","tryCatchPattern":"// guard before unwrapping:\nif let Event::EntityDropItemEvent(data) = event {\n    // use data\n} else {\n    log::error!(\"misrouted event: expected EntityDropItemEvent\");\n}","preventionTips":["Match the exact `Event` variant before downcasting","Never reuse one event impl's `data_from_event` for another event's payload in tests","Add round-trip unit tests for every event type","Keep plugin-api versions synchronized"],"tags":["rust","panic","event-dispatch","plugin-api"],"backgroundTag":"internal-invariant-violation","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"}