Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires inside `FromIntoEvent::data_from_event` for `AsyncStructureGenerateEvent` when the passed `Event` is not `Event::AsyncStructureGenerateEvent`. The macro-generated plugin method pipeline uses this conversion to unwrap typed data after `EVENT_TYPE`-based routing, so a foreign variant signals a misrouted or hand-constructed event and aborts the plugin thread.

Solutions

  1. Fix the host dispatcher so handlers receive only events matching their `EVENT_TYPE`.
  2. Rebuild plugin and host from the same pumpkin-plugin-api/WIT revision.
  3. Construct `Event::AsyncStructureGenerateEvent(data)` before invoking the handler in custom code.
  4. Verify registration macros map each handler to exactly one `EventType`.

Example fix

// before
Event::AsyncStructureGenerateEvent(data) => data,
_ => panic!("unexpected event"),
// after (harness guard)
Event::AsyncStructureGenerateEvent(data) => data,
other => unreachable!("AsyncStructureGenerate handler got {:?}", other.event_type()),
Defensive patterns

Strategy: type-guard

Validate before calling

assert!(matches!(event, Event::AsyncStructureGenerateEvent(_)), "handler requires Event::AsyncStructureGenerateEvent");

Type guard

fn as_async_structure_generate(ev: &Event) -> Option<&AsyncStructureGenerateEventData> {
    if let Event::AsyncStructureGenerateEvent(d) = ev { Some(d) } else { None }
}

Try / catch

// guard before invoking macro-generated handler:
if let Event::AsyncStructureGenerateEvent(data) = event { handle(data) } else { log::warn!("foreign event at structure-generate handler") }

Prevention

When it happens

Trigger: Routing any other world event (e.g. `Event::ChunkLoadEvent`) to an `AsyncStructureGenerateEvent` handler, or calling the conversion directly with a mismatched `Event` in a custom harness.

Common situations: Custom event buses whose routing key disagrees with the payload; plugin compiled against a different `Event` enum than the host (WIT/version skew); tests reusing events across handlers.

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

Appendix: source

Thrown at crates/pumpkin-plugin-api/src/events/world/async_structure_generate.rs:13

use super::super::FromIntoEvent;
use crate::wit::pumpkin::plugin::event::{AsyncStructureGenerateEventData, Event, EventType};

/// Event triggered when a structure is asynchronously generated.
pub struct AsyncStructureGenerateEvent;
impl FromIntoEvent for AsyncStructureGenerateEvent {
    const EVENT_TYPE: EventType = EventType::AsyncStructureGenerateEvent;
    type Data = AsyncStructureGenerateEventData;

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

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

View on GitHub (pinned to 8d4639e25a)