Pumpkin-MC/Pumpkin · error
unexpected event
Error message
unexpected event
What it means
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.
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
Example fix
// before <EntityExhaustionEvent as Event>::data_from_event(Event::EntityRegainHealthEvent(d)); // after <EntityExhaustionEvent as Event>::data_from_event(Event::EntityExhaustionEvent(d));
Defensive patterns
Strategy: type-guard
Validate before calling
if !matches!(event, Event::EntityExhaustionEvent(_)) { return; }
<crate::events::entity::entity_exhaustion::EntityExhaustionEvent as Event>::data_from_event(event); Type guard
fn as_entity_exhaustion(event: &Event) -> Option<&EntityExhaustionEventData> {
match event { Event::EntityExhaustionEvent(d) => Some(d), _ => None }
} Try / catch
// guard before unwrapping:
if let Event::EntityExhaustionEvent(data) = event {
// use data
} else {
log::error!("misrouted event: expected EntityExhaustionEvent");
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Copy-paste dispatch in test harnesses; event buses that skip `EventType` verification; plugin-api/server version drift.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/06284c4d94e32462.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-plugin-api/src/events/entity/entity_exhaustion.rs:14
use crate::wit::pumpkin::plugin::event::{EntityExhaustionEventData, Event, EventType};
use super::super::FromIntoEvent;
/// Event triggered when an entity experiences hunger exhaustion.
pub struct EntityExhaustionEvent;
impl FromIntoEvent for EntityExhaustionEvent {
const EVENT_TYPE: EventType = EventType::EntityExhaustionEvent;
type Data = EntityExhaustionEventData;
fn data_from_event(event: Event) -> Self::Data {
match event {
Event::EntityExhaustionEvent(data) => data,
_ => panic!("unexpected event"),
}
}
fn data_into_event(data: Self::Data) -> Event {
Event::EntityExhaustionEvent(data)
}
}
View on GitHub (pinned to 8d4639e25a)