Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires inside `data_from_event` for EntityDropItemEvent when the incoming `Event` is not `Event::EntityDropItemEvent`. The function unwraps the generic `Event` enum into `EntityDropItemEventData`, and the catch-all panics on any other variant since the dispatcher contract guarantees a match. It indicates the event was misrouted or manually constructed with the wrong variant.

Solutions

  1. Route the event as `Event::EntityDropItemEvent(data)` before calling `data_from_event`
  2. Check `EVENT_TYPE`/`event_type()` before forwarding an `Event` through a handler
  3. Keep plugin-api and host versions in sync so `Event` variants correspond
  4. Handle the mismatch arm gracefully (log and skip) instead of panicking in production paths

Example fix

// before
<EntityDropItemEvent as Event>::data_from_event(Event::EntityDyeEvent(dye_data));
// after
<EntityDropItemEvent as Event>::data_from_event(Event::EntityDropItemEvent(drop_data));
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

fn as_entity_drop_item(event: &Event) -> Option<&EntityDropItemEventData> {
    match event { Event::EntityDropItemEvent(d) => Some(d), _ => None }
}

Try / catch

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

Prevention

When it happens

Trigger: Passing a non-`EntityDropItemEvent` variant into `data_from_event` — manual dispatch with the wrong variant, a dispatcher bug pairing `EventType::EntityDropItemEvent` with foreign data, or test code that feeds unrelated events through this implementation.

Common situations: Copy-paste mistakes in custom dispatch/test harnesses; plugin registries that forward raw `Event` values without checking the declared `EventType`; mixed plugin-api versions causing variant mismatch.

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/8fa46f5f2e5ff745. Report an issue: GitHub.

Appendix: source

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

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

use super::super::FromIntoEvent;

/// Event triggered when an entity drops an item.
pub struct EntityDropItemEvent;
impl FromIntoEvent for EntityDropItemEvent {
    const EVENT_TYPE: EventType = EventType::EntityDropItemEvent;
    type Data = EntityDropItemEventData;

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

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

View on GitHub (pinned to 8d4639e25a)