Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires inside `data_from_event` for EntityEnterBlockEvent when the incoming `Event` is not `Event::EntityEnterBlockEvent`. The function's job is to unwrap the generic `Event` enum into `EntityEnterBlockEventData`, and the catch-all panics on any other variant because the dispatcher contract guarantees only the matching variant arrives. Hitting it means routing delivered the wrong payload.

Solutions

  1. Dispatch only `Event::EntityEnterBlockEvent(data)` through this handler
  2. Guard with an `EventType` check before unwrapping
  3. Keep host and plugin-api versions aligned
  4. Convert the panic arm into a logged error/`Result` for graceful handling

Example fix

// before
<EntityEnterBlockEvent as Event>::data_from_event(Event::EntityExitBlockEvent(d));
// after
<EntityEnterBlockEvent as Event>::data_from_event(Event::EntityEnterBlockEvent(d));
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

fn as_entity_enter_block(event: &Event) -> Option<&EntityEnterBlockEventData> {
    match event { Event::EntityEnterBlockEvent(d) => Some(d), _ => None }
}

Try / catch

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

Prevention

When it happens

Trigger: Feeding a non-matching `Event` variant into `data_from_event` — manual dispatch with the wrong variant, dispatcher bug pairing `EventType::EntityEnterBlockEvent` with foreign data, or a test harness reusing this impl for other events.

Common situations: Copy-pasted dispatch code in plugin tests; event forwarding that ignores the declared `EventType`; plugin-api version mismatch changing the `Event` enum.

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/050240e4cb1f27d2. Report an issue: GitHub.

Appendix: source

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

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

use super::super::FromIntoEvent;

/// Event triggered when an entity enters a block.
pub struct EntityEnterBlockEvent;
impl FromIntoEvent for EntityEnterBlockEvent {
    const EVENT_TYPE: EventType = EventType::EntityEnterBlockEvent;
    type Data = EntityEnterBlockEventData;

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

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

View on GitHub (pinned to 8d4639e25a)