{"record":{"id":"b922c533501f5daf","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-b922c5","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_dismount.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntityDismountEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when an entity dismounts another entity.\npub struct EntityDismountEvent;\nimpl FromIntoEvent for EntityDismountEvent {\n    const EVENT_TYPE: EventType = EventType::EntityDismountEvent;\n    type Data = EntityDismountEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntityDismountEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntityDismountEvent(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_dismount.rs#L1-L22","documentation":"This panic fires inside `data_from_event` for EntityDismountEvent when the incoming `Event` is not `Event::EntityDismountEvent`. The function exists to unwrap the generic `Event` enum into the concrete `EntityDismountEventData`; the catch-all arm treats any other variant as an impossible state, because the dispatcher contract guarantees only matching variants are delivered. Hitting it means event routing delivered a mismatched payload.","triggerScenarios":"Invoking the `Event` trait's `data_from_event` with any variant other than `Event::EntityDismountEvent` — manual dispatch with the wrong variant, a dispatcher that pairs `EventType::EntityDismountEvent` with the wrong data, or test harness code feeding arbitrary events through the wrong implementation.","commonSituations":"Copy-pasted dispatch code in tests using a neighboring event variant; custom event-bus code that stores `Event` values and forwards them without checking `EVENT_TYPE`; version skew between plugin-api crates where variant names drifted.","solutions":["Verify the event is routed/dispatched as `Event::EntityDismountEvent` before reaching `data_from_event`","In manual dispatch code, match on the variant yourself or check `event_type()` equals `EventType::EntityDismountEvent` first","Align plugin-api versions across server and plugin so the `Event` enum layout is identical","Soften the catch-all to return a `Result`/log instead of panicking if robustness matters more than strictness"],"exampleFix":"// before\nmatch event {\n    Event::EntityDeathEvent(d) => <EntityDismountEvent as Event>::data_from_event(Event::EntityDeathEvent(d)),\n    _ => unreachable!(),\n}\n// after\nmatch event {\n    Event::EntityDismountEvent(d) => <EntityDismountEvent as Event>::data_from_event(Event::EntityDismountEvent(d)),\n    _ => unreachable!(),\n}","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::EntityDismountEvent(_)) { return; }\n<crate::events::entity::entity_dismount::EntityDismountEvent as Event>::data_from_event(event);","typeGuard":"fn as_entity_dismount(event: &Event) -> Option<&EntityDismountEventData> {\n    match event { Event::EntityDismountEvent(d) => Some(d), _ => None }\n}","tryCatchPattern":"// guard before unwrapping:\nif let Event::EntityDismountEvent(data) = event {\n    // use data\n} else {\n    log::error!(\"misrouted event: expected EntityDismountEvent\");\n}","preventionTips":["Pattern-match the expected variant before invoking `data_from_event`","Avoid forwarding raw `Event` values through handlers without checking `EVENT_TYPE`","Round-trip test each event implementation (`data_into_event` then `data_from_event`)","Pin matching versions of plugin-api across plugin and host"],"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"}