Pumpkin-MC/Pumpkin · error
unexpected event
Error message
unexpected event
What it means
This panic fires inside `FromIntoEvent::data_from_event` for `ChunkSaveEvent` when the passed `Event` is not `Event::ChunkSaveEvent`. This impl unwraps the typed save payload after type-keyed routing; any other variant violates the library invariant that handlers only see their registered event type and causes a panic in the plugin thread.
Solutions
- Correct the dispatcher mapping so save handlers receive only `Event::ChunkSaveEvent`.
- Rebuild plugin and host from one API version to remove `Event` enum drift.
- Construct `Event::ChunkSaveEvent(data)` explicitly before invoking handlers in a harness.
- Add a debug assertion that `ev.event_type() == EventType::ChunkSaveEvent` prior to conversion.
Example fix
// before
Event::ChunkSaveEvent(data) => data,
_ => panic!("unexpected event"),
// after (diagnostic)
Event::ChunkSaveEvent(data) => data,
other => unreachable!("ChunkSave handler got {:?}", other.event_type()), Defensive patterns
Strategy: type-guard
Validate before calling
assert!(matches!(event, Event::ChunkSaveEvent(_)), "handler requires Event::ChunkSaveEvent");
Type guard
fn as_chunk_save(ev: &Event) -> Option<&ChunkSaveEventData> {
if let Event::ChunkSaveEvent(d) = ev { Some(d) } else { None }
} Try / catch
// guard before dispatch:
if let Event::ChunkSaveEvent(data) = event { handle(data) } else { log::warn!("foreign event at chunk-save handler") } Prevention
- Confirm save handlers are registered under `EventType::ChunkSaveEvent`, not load/populate.
- Never hand-construct `Event` variants for dispatch.
- Rebuild plugin and host together after API updates.
- Add a startup assertion that every registered handler's `EVENT_TYPE` matches the events its bus sends.
When it happens
Trigger: Routing e.g. `Event::ChunkLoadEvent` into a `ChunkSaveEvent` handler, or calling the generated conversion directly with a mismatched `Event` in custom dispatch infrastructure.
Common situations: Custom hosts with swapped chunk event registrations; host/plugin ABI or WIT version skew after enum changes; test harnesses reusing a single `Event` value 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/f75340f8e2b51b2f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-plugin-api/src/events/world/chunk_save.rs:15
use crate::wit::pumpkin::plugin::event::{ChunkSaveEventData, Event, EventType};
use super::super::FromIntoEvent;
/// An event that occurs when a chunk is saved in a world.
pub struct ChunkSaveEvent;
impl FromIntoEvent for ChunkSaveEvent {
const EVENT_TYPE: EventType = EventType::ChunkSaveEvent;
type Data = ChunkSaveEventData;
fn data_from_event(event: Event) -> Self::Data {
match event {
Event::ChunkSaveEvent(data) => data,
_ => panic!("unexpected event"),
}
}
fn data_into_event(data: Self::Data) -> Event {
Event::ChunkSaveEvent(data)
}
}
View on GitHub (pinned to 8d4639e25a)