Pumpkin-MC/Pumpkin · error

unexpected event type

Error message

unexpected event type

What it means

The WASM plugin host's per-event-type conversion layer (`from_wasm_event`) received an `Event` variant other than `VehicleBlockCollisionEvent` and panics. Each vehicle event adapter is only ever supposed to be dispatched with its own variant; hitting the catch-all `_` arm means the event dispatch/matching table is out of sync with the event enum. This is an internal invariant of the plugin bridge, not a plugin author error.

Solutions

  1. Audit the event dispatch/matching code that calls `from_wasm_event` for the vehicle-block-collision adapter and ensure it only routes `Event::VehicleBlockCollisionEvent`
  2. Verify the core `Event` enum and the WIT v0_1 event enum are in sync (regenerate WIT bindings if they drifted)
  3. Replace the panic with a logged warning + event drop if a plugin API version may legitimately send unknown variants
  4. Write a unit test that constructs every `Event` variant and asserts it dispatches to its matching adapter

Example fix

// before
_ => panic!("unexpected event type"),
// after
other => log::warn!("event {:?} misrouted to VehicleBlockCollisionEvent handler; dropping", std::mem::discriminant(&other))
Defensive patterns

Strategy: type-guard

Validate before calling

// host-side guard before conversion
if !matches!(event, Event::VehicleBlockCollisionEvent(_)) {
    log::warn!("event misrouted to VehicleBlockCollisionEvent adapter");
    return;
}

Type guard

fn is_vehicle_block_collision(e: &Event) -> bool {
    matches!(e, Event::VehicleBlockCollisionEvent(_))
}

Try / catch

// panic is not catchable via Result; use catch_unwind at the dispatch boundary
let result = std::panic::catch_unwind(AssertUnwindSafe(|| adapter.from_wasm_event(event, state)));
if result.is_err() { log::error!("event conversion panicked; event dropped"); }

Prevention

When it happens

Trigger: Dispatching a plugin event to the VehicleBlockCollisionEvent handler with an `Event` enum variant other than `Event::VehicleBlockCollisionEvent` — i.e. a bug in the event router (crate event enum and WIT v0_1 dispatch table mismatched after adding/renaming a variant).

Common situations: Developers adding a new `Event` variant to the core enum but forgetting to register it in the WIT v0_1 event dispatch table; refactoring event names so the router falls through to the wrong handler; running a plugin built against a different API version whose event IDs are remapped.

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

Appendix: source

Thrown at crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/vehicle.rs:43

use pumpkin_util::math::vector3::Vector3;

impl ToFromWasmEvent for VehicleBlockCollisionEvent {
    fn to_wasm_event(&self, _state: &mut PluginHostState) -> Event {
        Event::VehicleBlockCollisionEvent(VehicleBlockCollisionEventData {
            vehicle_id: self.vehicle_id,
            block_pos: to_wasm_block_position(self.block_pos),
            cancelled: self.cancelled,
        })
    }

    fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {
        match event {
            Event::VehicleBlockCollisionEvent(data) => Self {
                vehicle_id: data.vehicle_id,
                block_pos: from_wasm_block_position(data.block_pos),
                cancelled: data.cancelled,
            },
            _ => panic!("unexpected event type"),
        }
    }

    fn apply_wasm_event(&mut self, event: Event, state: &mut PluginHostState) {
        cleanup_event(&event, state);
        if let Event::VehicleBlockCollisionEvent(data) = event {
            self.block_pos = from_wasm_block_position(data.block_pos);
            self.cancelled = data.cancelled;
        }
    }
}

impl ToFromWasmEvent for VehicleCollisionEvent {
    fn to_wasm_event(&self, _state: &mut PluginHostState) -> Event {
        Event::VehicleCollisionEvent(VehicleCollisionEventData {
            vehicle_id: self.vehicle_id,
            cancelled: self.cancelled,
        })

View on GitHub (pinned to 8d4639e25a)