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 `EntitySpellCastEvent`'s converter carries any variant other than `Event::EntitySpellCastEvent`. The trait bridges the WIT-generated `Event` enum to this event's typed `Data`, assuming dispatch always pairs the event type with its matching variant. A mismatched variant violates that invariant, so the library aborts rather than misreading the payload.

Solutions

  1. Keep host and pumpkin-plugin-api versions aligned so `EventType::EntitySpellCastEvent` maps to `Event::EntitySpellCastEvent`
  2. Ensure the dispatcher sends only `EventType::EntitySpellCastEvent` to this converter
  3. Check `EVENT_TYPE` before unwrapping in custom dispatch code
  4. Replace the panic with a `Result` or logged error

Example fix

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

Strategy: try-catch

Validate before calling

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

Type guard

fn as_entity_spell_cast(event: &Event) -> Option<&EntitySpellCastEventData> {
    match event {
        Event::EntitySpellCastEvent(data) => Some(data),
        _ => None,
    }
}

Try / catch

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

Prevention

When it happens

Trigger: `data_from_event` is invoked with an `Event` that is not `Event::EntitySpellCastEvent` — the dispatcher routed a different event to the `EntitySpellCastEvent` handler, or `EventType` tagging and the `Event` variant disagree (version skew or dispatch that ignores `EventType`).

Common situations: Host and plugin API version mismatch; a custom event bus forwarding raw `Event` values untyped; registering `EntitySpellCastEvent` under the wrong `EventType` key.

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

Appendix: source

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

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

use super::super::FromIntoEvent;

/// Event triggered when a spellcasting entity casts a spell.
pub struct EntitySpellCastEvent;
impl FromIntoEvent for EntitySpellCastEvent {
    const EVENT_TYPE: EventType = EventType::EntitySpellCastEvent;
    type Data = EntitySpellCastEventData;

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

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

View on GitHub (pinned to 8d4639e25a)