{"record":{"id":"050240e4cb1f27d2","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-050240","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_enter_block.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntityEnterBlockEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when an entity enters a block.\npub struct EntityEnterBlockEvent;\nimpl FromIntoEvent for EntityEnterBlockEvent {\n    const EVENT_TYPE: EventType = EventType::EntityEnterBlockEvent;\n    type Data = EntityEnterBlockEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntityEnterBlockEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntityEnterBlockEvent(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_enter_block.rs#L1-L22","documentation":"This panic fires inside `data_from_event` for EntityEnterBlockEvent when the incoming `Event` is not `Event::EntityEnterBlockEvent`. The function's job is to unwrap the generic `Event` enum into `EntityEnterBlockEventData`, and the catch-all panics on any other variant because the dispatcher contract guarantees only the matching variant arrives. Hitting it means routing delivered the wrong payload.","triggerScenarios":"Feeding a non-matching `Event` variant into `data_from_event` — manual dispatch with the wrong variant, dispatcher bug pairing `EventType::EntityEnterBlockEvent` with foreign data, or a test harness reusing this impl for other events.","commonSituations":"Copy-pasted dispatch code in plugin tests; event forwarding that ignores the declared `EventType`; plugin-api version mismatch changing the `Event` enum.","solutions":["Dispatch only `Event::EntityEnterBlockEvent(data)` through this handler","Guard with an `EventType` check before unwrapping","Keep host and plugin-api versions aligned","Convert the panic arm into a logged error/`Result` for graceful handling"],"exampleFix":"// before\n<EntityEnterBlockEvent as Event>::data_from_event(Event::EntityExitBlockEvent(d));\n// after\n<EntityEnterBlockEvent as Event>::data_from_event(Event::EntityEnterBlockEvent(d));","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::EntityEnterBlockEvent(_)) { return; }\n<crate::events::entity::entity_enter_block::EntityEnterBlockEvent as Event>::data_from_event(event);","typeGuard":"fn as_entity_enter_block(event: &Event) -> Option<&EntityEnterBlockEventData> {\n    match event { Event::EntityEnterBlockEvent(d) => Some(d), _ => None }\n}","tryCatchPattern":"// guard before unwrapping:\nif let Event::EntityEnterBlockEvent(data) = event {\n    // use data\n} else {\n    log::error!(\"misrouted event: expected EntityEnterBlockEvent\");\n}","preventionTips":["Check the `Event` variant before downcasting","Route events by their declared `EventType` in custom buses","Add round-trip tests per event type","Keep plugin-api and host versions in sync"],"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"}