{"record":{"id":"000a73781d071070","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-000a73","errorCode":null,"errorMessage":"unexpected event","messagePattern":"unexpected event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-plugin-api/src/events/inventory/brew.rs","lineNumber":13,"sourceCode":"use super::super::FromIntoEvent;\nuse crate::wit::pumpkin::plugin::event::{BrewEventData, Event, EventType};\n\n/// Event triggered when potion(s) finish brewing in a brewing stand.\npub struct BrewEvent;\nimpl FromIntoEvent for BrewEvent {\n    const EVENT_TYPE: EventType = EventType::BrewEvent;\n    type Data = BrewEventData;\n\n    fn data_from_event(event: Event) -> Self::Data {\n        match event {\n            Event::BrewEvent(data) => data,\n            _ => panic!(\"unexpected event\"),\n        }\n    }\n\n    fn data_into_event(data: Self::Data) -> Event {\n        Event::BrewEvent(data)\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-plugin-api/src/events/inventory/brew.rs#L1-L21","documentation":"This panic fires in `data_from_event`, the `Event` trait implementation for `BrewEvent`. The method extracts data only from `Event::BrewEvent(data)`; any other variant means the dispatcher sent an event of the wrong type to this brewing handler. This violates the library's dispatch contract, so it panics with \"unexpected event\".","triggerScenarios":"Passing an `Event` other than `Event::BrewEvent` to `data_from_event`, e.g. dispatching `FurnaceBurnEvent` to the brew handler or registering the handler under a mismatched `EventType`.","commonSituations":"Misregistered inventory-event handlers, custom dispatch code that maps `EventType` to handlers incorrectly, or version skew between server and plugin after an `Event` enum change.","solutions":["Register the handler for `EventType::BrewEvent` so the dispatcher only sends `BrewEvent` payloads.","Ensure manual calls construct the event via `BrewEvent::data_into_event(data)` before extraction.","Synchronize pumpkin-plugin-api versions across the workspace and rebuild cleanly.","Pre-check the variant: `if let Event::BrewEvent(data) = event { ... }`.","Return `None`/log instead of panicking to keep the server alive on a routing bug."],"exampleFix":"// before\nmatch event {\n    Event::BrewEvent(data) => data,\n    _ => panic!(\"unexpected event\"),\n}\n// after\nmatch event {\n    Event::BrewEvent(data) => data,\n    _ => panic!(\"BrewEvent handler received non-BrewEvent payload\"),\n}","handlingStrategy":"type-guard","validationCode":"// Before dispatch\nassert_eq!(event.event_type(), EventType::BrewEvent, \"wrong event routed to Brew handler\");","typeGuard":"fn as_brew(event: &Event) -> Option<&BrewEventData> {\n    match event {\n        Event::BrewEvent(data) => Some(data),\n        _ => None,\n    }\n}","tryCatchPattern":"let result = std::panic::catch_unwind(AssertUnwindSafe(|| handler.data_from_event(event)));\nif result.is_err() {\n    log::error!(\"BrewEvent handler received an unexpected event variant\");\n}","preventionTips":["Register inventory handlers with their exact EventType (EventType::BrewEvent here).","Pre-narrow with if-let before calling data_from_event manually.","Use data_into_event to construct events so the variant always matches the type.","Sync pumpkin-plugin-api versions across crates; clean rebuild on upgrade.","Don't conflate inventory event types in a shared dispatch table without per-type checks."],"tags":["rust","panic","event-dispatch","inventory"],"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"}