Pumpkin-MC/Pumpkin · error
unexpected event
Error message
unexpected event
What it means
This panic fires inside `FromIntoEvent::data_from_event` for `AsyncStructureSpawnEvent` when the passed `Event` variant is anything other than `Event::AsyncStructureSpawnEvent`. The conversion unwraps typed payload after type-based routing; receiving any other variant violates the invariant that the event bus delivers only matching events and results in a panic inside the plugin handler.
Solutions
- Correct routing so only `Event::AsyncStructureSpawnEvent` reaches this handler.
- Align plugin API versions between host and plugin to eliminate enum drift.
- Construct `Event::AsyncStructureSpawnEvent(data)` explicitly in custom harnesses.
- Add a debug assertion comparing `event.event_type()` with `EventType::AsyncStructureSpawnEvent` before conversion.
Example fix
// before handler(Event::ChunkLoadEvent(data)) // wrong variant // after handler(Event::AsyncStructureSpawnEvent(data))
Defensive patterns
Strategy: type-guard
Validate before calling
assert!(matches!(event, Event::AsyncStructureSpawnEvent(_)), "handler requires Event::AsyncStructureSpawnEvent");
Type guard
fn as_async_structure_spawn(ev: &Event) -> Option<&AsyncStructureSpawnEventData> {
if let Event::AsyncStructureSpawnEvent(d) = ev { Some(d) } else { None }
} Try / catch
// guard before dispatch:
if let Event::AsyncStructureSpawnEvent(data) = event { handle(data) } else { log::warn!("non-spawn event in structure-spawn handler") } Prevention
- Key custom event buses on `EventType` and carry only the matching variant.
- Sync host/plugin versions to avoid `Event` enum drift.
- Avoid sharing one event fixture across multiple handlers in tests.
- Validate registration tables with a startup self-check.
When it happens
Trigger: Dispatching a foreign event variant to an `AsyncStructureSpawnEvent` handler, or a custom plugin harness invoking the generated conversion with a mismatched `Event`.
Common situations: Hand-written dispatch tables in alternate hosts; host/plugin ABI skew where `Event` variants changed; test fixtures passing one shared event to multiple 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/cbad2619e92ebd89.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-plugin-api/src/events/world/async_structure_spawn.rs:13
use super::super::FromIntoEvent;
use crate::wit::pumpkin::plugin::event::{AsyncStructureSpawnEventData, Event, EventType};
/// Event triggered when a structure is asynchronously spawned.
pub struct AsyncStructureSpawnEvent;
impl FromIntoEvent for AsyncStructureSpawnEvent {
const EVENT_TYPE: EventType = EventType::AsyncStructureSpawnEvent;
type Data = AsyncStructureSpawnEventData;
fn data_from_event(event: Event) -> Self::Data {
match event {
Event::AsyncStructureSpawnEvent(data) => data,
_ => panic!("unexpected event"),
}
}
fn data_into_event(data: Self::Data) -> Event {
Event::AsyncStructureSpawnEvent(data)
}
}
View on GitHub (pinned to 8d4639e25a)