{"record":{"id":"823659910c2c9bd0","repo":"Pumpkin-MC/Pumpkin","slug":"unexpected-event-type-823659","errorCode":null,"errorMessage":"unexpected event type","messagePattern":"unexpected event type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/server.rs","lineNumber":80,"sourceCode":"\n    fn apply_wasm_event(&mut self, event: Event, state: &mut PluginHostState) {\n        cleanup_event(&event, state);\n        if let Event::PacketReceivedEvent(data) = event {\n            self.packet_id = data.packet_id;\n            self.payload = data.raw_payload.into();\n            self.cancelled = data.cancelled;\n        }\n    }\n    fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {\n        match event {\n            Event::PacketReceivedEvent(_) => {\n                // TODO: Implement converting from WIT variant back to raw if needed.\n                // For now, we only support cancellation.\n                panic!(\n                    \"Modifying packets from WASM is not yet supported in this simple implementation.\"\n                );\n            }\n            _ => panic!(\"unexpected event type\"),\n        }\n    }\n}\n\nimpl ToFromWasmEvent for PacketSentEvent {\n    fn to_wasm_event(&self, state: &mut PluginHostState) -> Event {\n        let player_res = state\n            .add_player(self.player.clone())\n            .expect(\"failed to add player resource\");\n\n        let packet = match self.player.client.as_ref() {\n            ClientPlatform::Java(_) => {\n                generated_packets::clientbound_java_any_to_wit(self.packet.as_ref())\n                    .map_or(ClientboundPacket::Unknown, ClientboundPacket::Java)\n            }\n            ClientPlatform::Bedrock(_) => {\n                generated_packets::clientbound_bedrock_any_to_wit(self.packet.as_ref())\n                    .map_or(ClientboundPacket::Unknown, ClientboundPacket::Bedrock)","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/server.rs#L62-L98","documentation":"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.","triggerScenarios":"The host routes any Event variant other than Event::PacketReceivedEvent (e.g. PacketSentEvent or ServerCommandEvent) into PacketReceivedEvent::from_wasm_event.","commonSituations":"Dispatch table miswiring after adding new server event variants; plugin subscribed to one event but host delivers another; refactoring changed variant names/order.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// host side, before calling the converter\nassert!(matches!(event, Event::PacketReceivedEvent(_)), \"event/converter mismatch\");","typeGuard":"fn is_packet_received(e: &Event) -> bool { matches!(e, Event::PacketReceivedEvent(_)) }","tryCatchPattern":"let out = catch_unwind(|| PacketReceivedEvent::from_wasm_event(event, state))\n    .unwrap_or_else(|_| log_and_default());","preventionTips":["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"],"tags":["wasm","plugin","events","panic","invariant-violation"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}