{"record":{"id":"27988ade5007bd85","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-27988a","errorCode":null,"errorMessage":"unexpected event","messagePattern":"unexpected event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-plugin-api/src/events/server/map_initialize.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{Event, EventType, MapInitializeEventData};\n\nuse super::super::FromIntoEvent;\n\n/// An event that occurs when a map is initialized.\npub struct MapInitializeEvent;\nimpl FromIntoEvent for MapInitializeEvent {\n    const EVENT_TYPE: EventType = EventType::MapInitializeEvent;\n    type Data = MapInitializeEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::MapInitializeEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::MapInitializeEvent(data)\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-plugin-api/src/events/server/map_initialize.rs#L1-L22","documentation":"This panic fires inside the `data_from_event` conversion for MapInitializeEvent. The conversion accepts only `Event::MapInitializeEvent` and panics with \"unexpected event\" for anything else, enforcing the invariant that the dispatcher delivers exactly the matching variant to each typed handler. Hitting the panic means a different event reached this handler.","triggerScenarios":"Calling `data_from_event` with any `Event` variant besides `Event::MapInitializeEvent` — e.g. world/map events being converted through this handler, or a handler registered under a mismatched EventType receiving another payload.","commonSituations":"Sharing one conversion across world-related handlers; version skew where the `Event` enum was reordered or renamed so dispatch lands on the wrong variant; plugin test harnesses pushing the wrong `Event` through the conversion.","solutions":["Register the map-initialize handler with EventType::MapInitializeEvent and use its dedicated conversion only.","Match on `Event::MapInitializeEvent` before calling `data_from_event`.","Align plugin and server versions so `Event` variants are dispatched identically on both sides.","If the bus delivers the wrong variant, add debug logging of the variant and report a dispatcher bug."],"exampleFix":"// before\nlet data = MapInitializeEvent::data_from_event(event); // panics on other events\n// after\nif let Event::MapInitializeEvent(_) = event {\n    let data = MapInitializeEvent::data_from_event(event);\n}","handlingStrategy":"type-guard","validationCode":"let is_expected = matches!(event, Event::MapInitializeEvent(_));\nif !is_expected { /* skip */ }","typeGuard":"fn is_map_initialize(event: &Event) -> bool {\n    matches!(event, Event::MapInitializeEvent(_))\n}","tryCatchPattern":"if let Event::MapInitializeEvent(_) = event {\n    let data = MapInitializeEvent::data_from_event(event);\n} else {\n    log::warn!(\"unexpected event in map-initialize handler\");\n}","preventionTips":["Register map-initialize with EventType::MapInitializeEvent and use only its conversion.","Guard conversions with matches! checks.","Sync plugin and server releases.","Route all events through a match on Event before typed handling."],"tags":["panic","events","plugin-api","rust","world"],"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"}