Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires in `FromIntoEvent::data_from_event` when an `Event` passed to `EntityTameEvent`'s converter carries any variant other than `Event::EntityTameEvent`. The trait bridges the WIT-generated `Event` enum to this event's typed `Data`, trusting dispatch to always pair event type with matching variant. A mismatch breaks that contract, so the library aborts instead of returning wrong data.

Solutions

  1. Sync host and pumpkin-plugin-api versions so `EventType::EntityTameEvent` maps to `Event::EntityTameEvent`
  2. Audit the dispatcher to route only `EventType::EntityTameEvent` to this converter
  3. Filter events by `EVENT_TYPE` before calling `data_from_event`
  4. Convert the panic to a `Result` or logged error for graceful handling

Example fix

// before
match event {
    Event::EntityTameEvent(data) => data,
    _ => panic!("unexpected event"),
}
// after
match event {
    Event::EntityTameEvent(data) => Ok(data),
    _ => Err("unexpected event"),
}
Defensive patterns

Strategy: try-catch

Validate before calling

if event.event_type() != EventType::EntityTameEvent {
    return; // skip: not an EntityTameEvent
}

Type guard

fn as_entity_tame(event: &Event) -> Option<&EntityTameEventData> {
    match event {
        Event::EntityTameEvent(data) => Some(data),
        _ => None,
    }
}

Try / catch

let data = std::panic::catch_unwind(|| EntityTameEvent::data_from_event(event))
    .unwrap_or_else(|_| { log::error!("event type mismatch for EntityTameEvent"); return; });

Prevention

When it happens

Trigger: `data_from_event` is invoked with an `Event` that is not `Event::EntityTameEvent` — the dispatcher routed a different event to the `EntityTameEvent` handler, or the `EventType` tag and `Event` variant disagree due to version skew or unchecked dispatch.

Common situations: Mismatched host and plugin API versions; a custom event bus forwarding raw `Event` values without checking type; `EntityTameEvent` registered under the wrong `EventType` after refactoring.

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/701e76ff9c561398. Report an issue: GitHub.

Appendix: source

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

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

use super::super::FromIntoEvent;

/// Event triggered when an entity is tamed.
pub struct EntityTameEvent;
impl FromIntoEvent for EntityTameEvent {
    const EVENT_TYPE: EventType = EventType::EntityTameEvent;
    type Data = EntityTameEventData;

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

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

View on GitHub (pinned to 8d4639e25a)