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 `EntityShootBowEvent`'s converter carries any variant other than `Event::EntityShootBowEvent`. The trait bridges the WIT-generated `Event` enum to this event's typed `Data`, assuming the dispatch layer always pairs event type and variant. A mismatch means that invariant was violated and the library aborts rather than misinterpreting the payload.

Solutions

  1. Align host and plugin API versions so `EventType::EntityShootBowEvent` maps to `Event::EntityShootBowEvent`
  2. Ensure the dispatcher routes only `EventType::EntityShootBowEvent` to this converter
  3. In custom dispatch code, check `EVENT_TYPE` before unwrapping the event
  4. Convert the panic into a `Result` or logged error for graceful failure

Example fix

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

Strategy: try-catch

Validate before calling

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

Type guard

fn as_entity_shoot_bow(event: &Event) -> Option<&EntityShootBowEventData> {
    match event {
        Event::EntityShootBowEvent(data) => Some(data),
        _ => None,
    }
}

Try / catch

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

Prevention

When it happens

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

Common situations: Mismatched host and pumpkin-plugin-api versions; a custom event bus forwarding raw `Event` values untyped; registering `EntityShootBowEvent` 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/502307ef0bd3d9f1. Report an issue: GitHub.

Appendix: source

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

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

use super::super::FromIntoEvent;

/// Event triggered when an entity shoots a bow.
pub struct EntityShootBowEvent;
impl FromIntoEvent for EntityShootBowEvent {
    const EVENT_TYPE: EventType = EventType::EntityShootBowEvent;
    type Data = EntityShootBowEventData;

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

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

View on GitHub (pinned to 8d4639e25a)