Pumpkin-MC/Pumpkin · error

unexpected event type

Error message

unexpected event type

What it means

Wildcard `_ => panic!("unexpected event type")` in the `from_wasm_event` impl for `PlayerRecipeBookClickEvent` (player.rs). The converter asserts the incoming `Event` is exactly `Event::PlayerRecipeBookClickEvent`; any other variant means the host routed the event incorrectly.

Solutions

  1. Ensure the dispatcher maps Event::PlayerRecipeBookClickEvent to this impl exclusively.
  2. Rebuild host and plugins from the same pumpkin-api revision.
  3. Log the received variant in the panic message.
  4. Return a conversion error instead of panicking so one bad event cannot abort the host.

Example fix

// before
_ => panic!("unexpected event type"),
// after
other => panic!("PlayerRecipeBookClickEvent::from_wasm_event got {other:?}"),
Defensive patterns

Strategy: type-guard

Validate before calling

debug_assert!(matches!(event, Event::PlayerRecipeBookClickEvent(_)));

Type guard

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

Try / catch

std::panic::catch_unwind(|| from_wasm_event(event, state)).unwrap_or_else(|_| log_misroute())

Prevention

When it happens

Trigger: The WASM dispatch layer delivers a non-matching Event variant to this converter — from a stale dispatch table, mismatched wit bindings, or a newly added player event variant not wired into the conversion registry.

Common situations: Host/plugin version skew on v0_1 event enums, forks adding recipe-book variants, or macro-generated plugin_method dispatch out of sync with the hand-written impls.

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

Appendix: source

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

    fn apply_wasm_event(&mut self, event: Event, state: &mut PluginHostState) {
        cleanup_event(&event, state);
        if let Event::PlayerRecipeBookClickEvent(data) = event {
            self.cancelled = data.cancelled;
            self.recipe_id = data.recipe_id;
            self.make_all = data.make_all;
        }
    }

    fn from_wasm_event(event: Event, state: &mut PluginHostState) -> Self {
        match event {
            Event::PlayerRecipeBookClickEvent(data) => Self {
                player: consume_player(state, &data.player),
                recipe_id: data.recipe_id,
                make_all: data.make_all,
                cancelled: data.cancelled,
            },
            _ => panic!("unexpected event type"),
        }
    }
}

impl ToFromWasmEvent for PlayerRecipeBookSettingsChangeEvent {
    fn to_wasm_event(&self, state: &mut PluginHostState) -> Event {
        let player = state
            .add_player(self.player.clone())
            .expect("failed to add player resource");
        Event::PlayerRecipeBookSettingsChangeEvent(PlayerRecipeBookSettingsChangeEventData {
            player,
            book_type: self.book_type.clone(),
            is_open: self.is_open,
            is_filtering: self.is_filtering,
            cancelled: self.cancelled,
        })
    }

View on GitHub (pinned to 8d4639e25a)