Pumpkin-MC/Pumpkin · error
unexpected event type
Error message
unexpected event type
What it means
PacketReceivedEvent::from_wasm_event matches only Event::PacketReceivedEvent (which currently panics as unsupported) and panics with 'unexpected event type' for everything else. Reaching the catch-all means an event of a different kind was dispatched through this converter — a routing invariant violation in the WASM event plumbing.
Solutions
- Verify the dispatcher maps Event::PacketReceivedEvent exclusively to this converter.
- Align the plugin's event subscriptions with what the host actually forwards.
- Update dispatch code whenever the Event enum changes.
- Downgrade the panic to a logged, recoverable error in host code.
Defensive patterns
Strategy: type-guard
Validate before calling
// host side, before calling the converter assert!(matches!(event, Event::PacketReceivedEvent(_)), "event/converter mismatch");
Type guard
fn is_packet_received(e: &Event) -> bool { matches!(e, Event::PacketReceivedEvent(_)) } Try / catch
let out = catch_unwind(|| PacketReceivedEvent::from_wasm_event(event, state))
.unwrap_or_else(|_| log_and_default()); Prevention
- Keep one dispatch table mapping each variant to its converter
- Regenerate dispatch code with WIT binding changes
- Test routing exhaustively for all variants
- Prefer Result-returning converters over panic arms
When it happens
Trigger: The host routes any Event variant other than Event::PacketReceivedEvent (e.g. PacketSentEvent or ServerCommandEvent) into PacketReceivedEvent::from_wasm_event.
Common situations: Dispatch table miswiring after adding new server event variants; plugin subscribed to one event but host delivers another; refactoring changed variant names/order.
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
- Cannot construct BlockFertilizeEvent from WASM
- unexpected event type
- failed to add player resource
- failed to add world resource
- Cannot construct BlockMultiPlaceEvent from WASM
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/823659910c2c9bd0.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/server.rs:80
fn apply_wasm_event(&mut self, event: Event, state: &mut PluginHostState) {
cleanup_event(&event, state);
if let Event::PacketReceivedEvent(data) = event {
self.packet_id = data.packet_id;
self.payload = data.raw_payload.into();
self.cancelled = data.cancelled;
}
}
fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {
match event {
Event::PacketReceivedEvent(_) => {
// TODO: Implement converting from WIT variant back to raw if needed.
// For now, we only support cancellation.
panic!(
"Modifying packets from WASM is not yet supported in this simple implementation."
);
}
_ => panic!("unexpected event type"),
}
}
}
impl ToFromWasmEvent for PacketSentEvent {
fn to_wasm_event(&self, state: &mut PluginHostState) -> Event {
let player_res = state
.add_player(self.player.clone())
.expect("failed to add player resource");
let packet = match self.player.client.as_ref() {
ClientPlatform::Java(_) => {
generated_packets::clientbound_java_any_to_wit(self.packet.as_ref())
.map_or(ClientboundPacket::Unknown, ClientboundPacket::Java)
}
ClientPlatform::Bedrock(_) => {
generated_packets::clientbound_bedrock_any_to_wit(self.packet.as_ref())
.map_or(ClientboundPacket::Unknown, ClientboundPacket::Bedrock)View on GitHub (pinned to 8d4639e25a)