{"record":{"id":"f75340f8e2b51b2f","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-f75340","errorCode":null,"errorMessage":"unexpected event","messagePattern":"unexpected event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-plugin-api/src/events/world/chunk_save.rs","lineNumber":15,"sourceCode":"use crate::wit::pumpkin::plugin::event::{ChunkSaveEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// An event that occurs when a chunk is saved in a world.\npub struct ChunkSaveEvent;\n\nimpl FromIntoEvent for ChunkSaveEvent {\n    const EVENT_TYPE: EventType = EventType::ChunkSaveEvent;\n    type Data = ChunkSaveEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::ChunkSaveEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::ChunkSaveEvent(data)\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-plugin-api/src/events/world/chunk_save.rs#L1-L23","documentation":"This panic fires inside `FromIntoEvent::data_from_event` for `ChunkSaveEvent` when the passed `Event` is not `Event::ChunkSaveEvent`. This impl unwraps the typed save payload after type-keyed routing; any other variant violates the library invariant that handlers only see their registered event type and causes a panic in the plugin thread.","triggerScenarios":"Routing e.g. `Event::ChunkLoadEvent` into a `ChunkSaveEvent` handler, or calling the generated conversion directly with a mismatched `Event` in custom dispatch infrastructure.","commonSituations":"Custom hosts with swapped chunk event registrations; host/plugin ABI or WIT version skew after enum changes; test harnesses reusing a single `Event` value across handlers.","solutions":["Correct the dispatcher mapping so save handlers receive only `Event::ChunkSaveEvent`.","Rebuild plugin and host from one API version to remove `Event` enum drift.","Construct `Event::ChunkSaveEvent(data)` explicitly before invoking handlers in a harness.","Add a debug assertion that `ev.event_type() == EventType::ChunkSaveEvent` prior to conversion."],"exampleFix":"// before\nEvent::ChunkSaveEvent(data) => data,\n_ => panic!(\"unexpected event\"),\n// after (diagnostic)\nEvent::ChunkSaveEvent(data) => data,\nother => unreachable!(\"ChunkSave handler got {:?}\", other.event_type()),","handlingStrategy":"type-guard","validationCode":"assert!(matches!(event, Event::ChunkSaveEvent(_)), \"handler requires Event::ChunkSaveEvent\");","typeGuard":"fn as_chunk_save(ev: &Event) -> Option<&ChunkSaveEventData> {\n    if let Event::ChunkSaveEvent(d) = ev { Some(d) } else { None }\n}","tryCatchPattern":"// guard before dispatch:\nif let Event::ChunkSaveEvent(data) = event { handle(data) } else { log::warn!(\"foreign event at chunk-save handler\") }","preventionTips":["Confirm save handlers are registered under `EventType::ChunkSaveEvent`, not load/populate.","Never hand-construct `Event` variants for dispatch.","Rebuild plugin and host together after API updates.","Add a startup assertion that every registered handler's `EVENT_TYPE` matches the events its bus sends."],"tags":["rust","panic","events","plugin-api","world","chunk"],"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"}