{"record":{"id":"06284c4d94e32462","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-06284c","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_exhaustion.rs","lineNumber":14,"sourceCode":"use crate::wit::pumpkin::plugin::event::{EntityExhaustionEventData, Event, EventType};\n\nuse super::super::FromIntoEvent;\n\n/// Event triggered when an entity experiences hunger exhaustion.\npub struct EntityExhaustionEvent;\nimpl FromIntoEvent for EntityExhaustionEvent {\n    const EVENT_TYPE: EventType = EventType::EntityExhaustionEvent;\n    type Data = EntityExhaustionEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::EntityExhaustionEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::EntityExhaustionEvent(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_exhaustion.rs#L1-L22","documentation":"This panic fires inside `data_from_event` for EntityExhaustionEvent when the incoming `Event` is not `Event::EntityExhaustionEvent`. The function unwraps the generic `Event` enum into `EntityExhaustionEventData`, panicking on any other variant since the dispatcher contract guarantees a match. It fires when the event-routing invariant is violated.","triggerScenarios":"Passing a non-`EntityExhaustionEvent` variant into `data_from_event` — manual dispatch with the wrong variant, a dispatcher that pairs `EventType::EntityExhaustionEvent` with foreign data, or test code misusing the impl.","commonSituations":"Copy-paste dispatch in test harnesses; event buses that skip `EventType` verification; plugin-api/server version drift.","solutions":["Route only `Event::EntityExhaustionEvent(data)` through this handler","Verify the event's `EventType` before unwrapping","Keep plugin-api and host versions synchronized","Replace the panic with a logged error or `Option` return for resilience"],"exampleFix":"// before\n<EntityExhaustionEvent as Event>::data_from_event(Event::EntityRegainHealthEvent(d));\n// after\n<EntityExhaustionEvent as Event>::data_from_event(Event::EntityExhaustionEvent(d));","handlingStrategy":"type-guard","validationCode":"if !matches!(event, Event::EntityExhaustionEvent(_)) { return; }\n<crate::events::entity::entity_exhaustion::EntityExhaustionEvent as Event>::data_from_event(event);","typeGuard":"fn as_entity_exhaustion(event: &Event) -> Option<&EntityExhaustionEventData> {\n    match event { Event::EntityExhaustionEvent(d) => Some(d), _ => None }\n}","tryCatchPattern":"// guard before unwrapping:\nif let Event::EntityExhaustionEvent(data) = event {\n    // use data\n} else {\n    log::error!(\"misrouted event: expected EntityExhaustionEvent\");\n}","preventionTips":["Verify the variant with `matches!` before downcasting","Dispatch only via the event's own impl and `EVENT_TYPE`","Add round-trip unit tests for all event types","Keep plugin-api and host versions aligned"],"tags":["rust","panic","event-dispatch","plugin-api"],"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"}