Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires inside `data_from_event` for EntityDyeEvent when the incoming `Event` is not `Event::EntityDyeEvent`. It is the downcast step from the generic `Event` enum to `EntityDyeEventData`; the catch-all arm panics because the dispatcher is supposed to deliver only the matching variant. Reaching it signals an event-routing invariant violation.

Solutions

  1. Ensure events are wrapped as `Event::EntityDyeEvent(data)` before dispatch
  2. Validate `event_type() == EventType::EntityDyeEvent` before calling `data_from_event`
  3. Synchronize plugin-api versions between plugin and host
  4. Return a `Result`/log from the catch-all arm rather than panicking if you need resilience

Example fix

// before
<EntityDyeEvent as Event>::data_from_event(event); // event is Event::EntityExplodeEvent(..)
// after
if matches!(event, Event::EntityDyeEvent(_)) {
    <EntityDyeEvent as Event>::data_from_event(event);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if !matches!(event, Event::EntityDyeEvent(_)) { return; }
<crate::events::entity::entity_dye::EntityDyeEvent as Event>::data_from_event(event);

Type guard

fn as_entity_dye(event: &Event) -> Option<&EntityDyeEventData> {
    match event { Event::EntityDyeEvent(d) => Some(d), _ => None }
}

Try / catch

// guard before unwrapping:
if let Event::EntityDyeEvent(data) = event {
    // use data
} else {
    log::error!("misrouted event: expected EntityDyeEvent");
}

Prevention

When it happens

Trigger: Calling `data_from_event` with any `Event` variant other than `Event::EntityDyeEvent` — wrong-variant manual dispatch, a dispatcher mismatch between `EventType::EntityDyeEvent` and the payload, or harness code reusing the wrong trait impl.

Common situations: Test fixtures that build `Event` values by copy-paste from sibling event modules; custom event buses that skip the `EventType` check; version drift between plugin-api and the host server.

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/17f29dfd36989032. Report an issue: GitHub.

Appendix: source

Thrown at crates/pumpkin-plugin-api/src/events/entity/entity_dye.rs:14

use crate::wit::pumpkin::plugin::event::{EntityDyeEventData, Event, EventType};

use super::super::FromIntoEvent;

/// Event triggered when an entity is dyed.
pub struct EntityDyeEvent;
impl FromIntoEvent for EntityDyeEvent {
    const EVENT_TYPE: EventType = EventType::EntityDyeEvent;
    type Data = EntityDyeEventData;

    fn data_from_event(event: Event) -> Self::Data {
        match event {
            Event::EntityDyeEvent(data) => data,
            _ => panic!("unexpected event"),
        }
    }

    fn data_into_event(data: Self::Data) -> Event {
        Event::EntityDyeEvent(data)
    }
}

View on GitHub (pinned to 8d4639e25a)