{"record":{"id":"68505a1233811b1f","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-68505a","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_remove.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntityRemoveEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// An event that occurs when an entity is removed from the world.\npub struct EntityRemoveEvent;\nimpl FromIntoEvent for EntityRemoveEvent {\n    const EVENT_TYPE: EventType = EventType::EntityRemoveEvent;\n    type Data = EntityRemoveEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntityRemoveEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntityRemoveEvent(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_remove.rs#L1-L22","documentation":"This panic fires in `FromIntoEvent::data_from_event` when an `Event` passed to `EntityRemoveEvent`'s converter carries any variant other than `Event::EntityRemoveEvent`. The trait bridges the WIT-generated `Event` enum to a specific event's typed `Data`, and the match arm expects the host/plugin dispatch layer to always pair the event type with its matching variant. Receiving a mismatched variant means the event dispatch plumbing violated that pairing invariant, so the library aborts rather than silently coerce wrong data.","triggerScenarios":"The only call path is `data_from_event` invoked (indirectly via `FromIntoEvent` helpers) with an `Event` whose variant is not `Event::EntityRemoveEvent` — i.e. the dispatch layer routed an event of a different type to the `EntityRemoveEvent` handler, typically when `EVENT_TYPE` tagging and the `Event` enum variant disagree (version skew between host and plugin API, or a hand-written dispatch that ignores `EventType`).","commonSituations":"Plugin compiled against one pumpkin-plugin-api version while the host emits an older/newer `Event` enum ordering; a custom event bus that forwards raw `Event` values without checking `EventType`; a refactored dispatcher that registers `EntityRemoveEvent` under the wrong `EventType` key.","solutions":["Verify the host and the pumpkin-plugin-api crate use matching versions so `EventType::EntityRemoveEvent` maps to `Event::EntityRemoveEvent`","Check the event dispatch/registration code routes only `EventType::EntityRemoveEvent` to `EntityRemoveEvent`'s converter","If writing a dispatcher, filter events by `EVENT_TYPE` before calling `data_from_event`","Replace the panic with a logged error or `Result` return to fail gracefully instead of aborting the plugin host"],"exampleFix":"// before\nfn data_from_event(event: Event) -> Self::Data {\n    match event {\n        Event::EntityRemoveEvent(data) => data,\n        _ => panic!(\"unexpected event\"),\n    }\n}\n// after\nfn data_from_event(event: Event) -> Result<Self::Data, Event> {\n    match event {\n        Event::EntityRemoveEvent(data) => Ok(data),\n        other => Err(other),\n    }\n}","handlingStrategy":"try-catch","validationCode":"if event.event_type() != EventType::EntityRemoveEvent {\n    return; // skip: not an EntityRemoveEvent, do not feed to data_from_event\n}","typeGuard":"fn as_entity_remove(event: &Event) -> Option<&EntityRemoveEventData> {\n    match event {\n        Event::EntityRemoveEvent(data) => Some(data),\n        _ => None,\n    }\n}","tryCatchPattern":"let data = std::panic::catch_unwind(|| EntityRemoveEvent::data_from_event(event))\n    .unwrap_or_else(|_| { log::error!(\"event type mismatch for EntityRemoveEvent\"); return; });","preventionTips":["Always match host and pumpkin-plugin-api versions","Dispatch events by checking `EVENT_TYPE` before calling `data_from_event`","Never forward raw `Event` values across event-type handler boundaries","Keep `EventType` registration keys and `Event` variants in sync"],"tags":["rust","panic","event-dispatch","plugin-api","internal-invariant"],"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"}