Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires inside the `data_from_event` conversion for MapInitializeEvent. The conversion accepts only `Event::MapInitializeEvent` and panics with "unexpected event" for anything else, enforcing the invariant that the dispatcher delivers exactly the matching variant to each typed handler. Hitting the panic means a different event reached this handler.

Solutions

  1. Register the map-initialize handler with EventType::MapInitializeEvent and use its dedicated conversion only.
  2. Match on `Event::MapInitializeEvent` before calling `data_from_event`.
  3. Align plugin and server versions so `Event` variants are dispatched identically on both sides.
  4. If the bus delivers the wrong variant, add debug logging of the variant and report a dispatcher bug.

Example fix

// before
let data = MapInitializeEvent::data_from_event(event); // panics on other events
// after
if let Event::MapInitializeEvent(_) = event {
    let data = MapInitializeEvent::data_from_event(event);
}
Defensive patterns

Strategy: type-guard

Validate before calling

let is_expected = matches!(event, Event::MapInitializeEvent(_));
if !is_expected { /* skip */ }

Type guard

fn is_map_initialize(event: &Event) -> bool {
    matches!(event, Event::MapInitializeEvent(_))
}

Try / catch

if let Event::MapInitializeEvent(_) = event {
    let data = MapInitializeEvent::data_from_event(event);
} else {
    log::warn!("unexpected event in map-initialize handler");
}

Prevention

When it happens

Trigger: Calling `data_from_event` with any `Event` variant besides `Event::MapInitializeEvent` — e.g. world/map events being converted through this handler, or a handler registered under a mismatched EventType receiving another payload.

Common situations: Sharing one conversion across world-related handlers; version skew where the `Event` enum was reordered or renamed so dispatch lands on the wrong variant; plugin test harnesses pushing the wrong `Event` through the conversion.

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

Appendix: source

Thrown at crates/pumpkin-plugin-api/src/events/server/map_initialize.rs:14

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

use super::super::FromIntoEvent;

/// An event that occurs when a map is initialized.
pub struct MapInitializeEvent;
impl FromIntoEvent for MapInitializeEvent {
    const EVENT_TYPE: EventType = EventType::MapInitializeEvent;
    type Data = MapInitializeEventData;

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

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

View on GitHub (pinned to 8d4639e25a)