{"record":{"id":"e3ac43888acc7046","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-e3ac43","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_spell_cast.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntitySpellCastEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when a spellcasting entity casts a spell.\npub struct EntitySpellCastEvent;\nimpl FromIntoEvent for EntitySpellCastEvent {\n    const EVENT_TYPE: EventType = EventType::EntitySpellCastEvent;\n    type Data = EntitySpellCastEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntitySpellCastEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntitySpellCastEvent(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_spell_cast.rs#L1-L22","documentation":"This panic fires in `FromIntoEvent::data_from_event` when an `Event` passed to `EntitySpellCastEvent`'s converter carries any variant other than `Event::EntitySpellCastEvent`. The trait bridges the WIT-generated `Event` enum to this event's typed `Data`, assuming dispatch always pairs the event type with its matching variant. A mismatched variant violates that invariant, so the library aborts rather than misreading the payload.","triggerScenarios":"`data_from_event` is invoked with an `Event` that is not `Event::EntitySpellCastEvent` — the dispatcher routed a different event to the `EntitySpellCastEvent` handler, or `EventType` tagging and the `Event` variant disagree (version skew or dispatch that ignores `EventType`).","commonSituations":"Host and plugin API version mismatch; a custom event bus forwarding raw `Event` values untyped; registering `EntitySpellCastEvent` under the wrong `EventType` key.","solutions":["Keep host and pumpkin-plugin-api versions aligned so `EventType::EntitySpellCastEvent` maps to `Event::EntitySpellCastEvent`","Ensure the dispatcher sends only `EventType::EntitySpellCastEvent` to this converter","Check `EVENT_TYPE` before unwrapping in custom dispatch code","Replace the panic with a `Result` or logged error"],"exampleFix":"// before\nmatch event {\n    Event::EntitySpellCastEvent(data) => data,\n    _ => panic!(\"unexpected event\"),\n}\n// after\nmatch event {\n    Event::EntitySpellCastEvent(data) => Ok(data),\n    _ => Err(\"unexpected event\"),\n}","handlingStrategy":"try-catch","validationCode":"if event.event_type() != EventType::EntitySpellCastEvent {\n    return; // skip: not an EntitySpellCastEvent\n}","typeGuard":"fn as_entity_spell_cast(event: &Event) -> Option<&EntitySpellCastEventData> {\n    match event {\n        Event::EntitySpellCastEvent(data) => Some(data),\n        _ => None,\n    }\n}","tryCatchPattern":"let data = std::panic::catch_unwind(|| EntitySpellCastEvent::data_from_event(event))\n    .unwrap_or_else(|_| { log::error!(\"event type mismatch for EntitySpellCastEvent\"); return; });","preventionTips":["Align host and plugin API versions","Dispatch by `EVENT_TYPE` before unwrapping","Never share one handler across unrelated `Event` variants","Test the dispatcher's type-to-variant mapping"],"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"}