Pumpkin-MC/Pumpkin · error

unexpected event

Error message

unexpected event

What it means

This panic fires in `data_from_event`, the `Event` trait implementation for `BrewEvent`. The method extracts data only from `Event::BrewEvent(data)`; any other variant means the dispatcher sent an event of the wrong type to this brewing handler. This violates the library's dispatch contract, so it panics with "unexpected event".

Solutions

  1. Register the handler for `EventType::BrewEvent` so the dispatcher only sends `BrewEvent` payloads.
  2. Ensure manual calls construct the event via `BrewEvent::data_into_event(data)` before extraction.
  3. Synchronize pumpkin-plugin-api versions across the workspace and rebuild cleanly.
  4. Pre-check the variant: `if let Event::BrewEvent(data) = event { ... }`.
  5. Return `None`/log instead of panicking to keep the server alive on a routing bug.

Example fix

// before
match event {
    Event::BrewEvent(data) => data,
    _ => panic!("unexpected event"),
}
// after
match event {
    Event::BrewEvent(data) => data,
    _ => panic!("BrewEvent handler received non-BrewEvent payload"),
}
Defensive patterns

Strategy: type-guard

Validate before calling

// Before dispatch
assert_eq!(event.event_type(), EventType::BrewEvent, "wrong event routed to Brew handler");

Type guard

fn as_brew(event: &Event) -> Option<&BrewEventData> {
    match event {
        Event::BrewEvent(data) => Some(data),
        _ => None,
    }
}

Try / catch

let result = std::panic::catch_unwind(AssertUnwindSafe(|| handler.data_from_event(event)));
if result.is_err() {
    log::error!("BrewEvent handler received an unexpected event variant");
}

Prevention

When it happens

Trigger: Passing an `Event` other than `Event::BrewEvent` to `data_from_event`, e.g. dispatching `FurnaceBurnEvent` to the brew handler or registering the handler under a mismatched `EventType`.

Common situations: Misregistered inventory-event handlers, custom dispatch code that maps `EventType` to handlers incorrectly, or version skew between server and plugin after an `Event` enum change.

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

Appendix: source

Thrown at crates/pumpkin-plugin-api/src/events/inventory/brew.rs:13

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

/// Event triggered when potion(s) finish brewing in a brewing stand.
pub struct BrewEvent;
impl FromIntoEvent for BrewEvent {
    const EVENT_TYPE: EventType = EventType::BrewEvent;
    type Data = BrewEventData;

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

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

View on GitHub (pinned to 8d4639e25a)