{"record":{"id":"4be809da539a33b7","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-4be809","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_spawn.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntitySpawnEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when an entity spawns in the world.\npub struct EntitySpawnEvent;\nimpl FromIntoEvent for EntitySpawnEvent {\n    const EVENT_TYPE: EventType = EventType::EntitySpawnEvent;\n    type Data = EntitySpawnEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntitySpawnEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntitySpawnEvent(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_spawn.rs#L1-L22","documentation":"This panic fires in `FromIntoEvent::data_from_event` when an `Event` passed to `EntitySpawnEvent`'s converter carries any variant other than `Event::EntitySpawnEvent`. The trait bridges the WIT-generated `Event` enum to this event's typed `Data`, trusting that dispatch always pairs event type with matching variant. A mismatch means the dispatch plumbing broke that contract, so the library aborts rather than returning wrong data.","triggerScenarios":"`data_from_event` is invoked with an `Event` that is not `Event::EntitySpawnEvent` — the dispatcher routed a different event to the `EntitySpawnEvent` handler, or the `EventType` tag and `Event` variant disagree due to version skew or unchecked dispatch.","commonSituations":"Host and plugin API versions out of sync; a custom event bus forwarding raw `Event` values without type checks; `EntitySpawnEvent` registered under the wrong `EventType` after a refactor.","solutions":["Match host and pumpkin-plugin-api versions so `EventType::EntitySpawnEvent` maps to `Event::EntitySpawnEvent`","Audit dispatch code to route only `EventType::EntitySpawnEvent` to this converter","Filter by `EVENT_TYPE` before calling `data_from_event`","Return a `Result` or log instead of panicking"],"exampleFix":"// before\nmatch event {\n    Event::EntitySpawnEvent(data) => data,\n    _ => panic!(\"unexpected event\"),\n}\n// after\nmatch event {\n    Event::EntitySpawnEvent(data) => Ok(data),\n    _ => Err(\"unexpected event\"),\n}","handlingStrategy":"try-catch","validationCode":"if event.event_type() != EventType::EntitySpawnEvent {\n    return; // skip: not an EntitySpawnEvent\n}","typeGuard":"fn as_entity_spawn(event: &Event) -> Option<&EntitySpawnEventData> {\n    match event {\n        Event::EntitySpawnEvent(data) => Some(data),\n        _ => None,\n    }\n}","tryCatchPattern":"let data = std::panic::catch_unwind(|| EntitySpawnEvent::data_from_event(event))\n    .unwrap_or_else(|_| { log::error!(\"event type mismatch for EntitySpawnEvent\"); return; });","preventionTips":["Keep host and pumpkin-plugin-api versions in sync","Check `EVENT_TYPE` before unwrapping","Route each `Event` variant to exactly one handler","Add dispatcher tests for type-to-variant pairing"],"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"}