{"record":{"id":"6e7e2bceb033629e","repo":"Pumpkin-MC/Pumpkin","slug":"cannot-construct-craftercraftevent-from-wasm","errorCode":null,"errorMessage":"Cannot construct CrafterCraftEvent from WASM","messagePattern":"Cannot construct CrafterCraftEvent from WASM","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/block.rs","lineNumber":1180,"sourceCode":"            .expect(\"failed to add item stack resource\");\n        Event::CrafterCraftEvent(CrafterCraftEventData {\n            block_pos: to_wasm_block_position(self.block_pos),\n            target_world,\n            result,\n            cancelled: self.cancelled,\n        })\n    }\n\n    fn apply_wasm_event(&mut self, event: Event, state: &mut PluginHostState) {\n        cleanup_event(&event, state);\n        if let Event::CrafterCraftEvent(data) = event {\n            self.cancelled = data.cancelled;\n        }\n    }\n\n    fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {\n        match event {\n            Event::CrafterCraftEvent(_) => panic!(\"Cannot construct CrafterCraftEvent from WASM\"),\n            _ => panic!(\"unexpected event type\"),\n        }\n    }\n}\n\nimpl ToFromWasmEvent for EntityBlockFormEvent {\n    fn to_wasm_event(&self, state: &mut PluginHostState) -> Event {\n        let target_world = state\n            .add_world(self.world.clone())\n            .expect(\"failed to add world resource\");\n        Event::EntityBlockFormEvent(EntityBlockFormEventData {\n            entity_id: self.entity.get_entity().entity_id,\n            block_pos: to_wasm_block_position(self.block_pos),\n            target_world,\n            new_state_id: self.new_state_id.as_u16(),\n            cancelled: self.cancelled,\n        })\n    }","sourceCodeStart":1162,"sourceCodeEnd":1198,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/block.rs#L1162-L1198","documentation":"`from_wasm_event` for CrafterCraftEvent unconditionally panics when it receives an Event::CrafterCraftEvent. This impl exists only to satisfy the trait; the crate deliberately forbids a plugin from *returning* a CrafterCraftEvent to the host (the event flows host->plugin only). Hitting this means a WASM plugin handed a CrafterCraftEvent back across the boundary.","triggerScenarios":"A plugin method whose WIT signature allows returning an Event returns Event::CrafterCraftEvent, and the host calls ToFromWasmEvent::from_wasm_event on it.","commonSituations":"A plugin (or generated bindings) misusing the event API by echoing/re-emitting the event object it received; a plugin language binding that constructs the wrong direction of event.","solutions":["Fix the plugin so it never returns the CrafterCraftEvent it received; consume it and return the expected value instead.","Check the plugin's generated bindings for a wrong return type on the event handler method.","Update the plugin SDK to match the host's WIT version so the handler's return type is correct.","If you need the host to observe the event, use the cancellation/data-mutation API rather than returning the event."],"exampleFix":"// plugin side, before\nfn on_craft(event: CrafterCraftEvent) -> Event { Event::CrafterCraftEvent(event) }\n// after\nfn on_craft(event: CrafterCraftEvent) -> Event { let _ = event; /* handle, don't re-emit */ }\n","handlingStrategy":"validation","validationCode":"// plugin side: never return the event object you received\nassert!(!matches!(return_value, Some(Event::CrafterCraftEvent(_))), \"do not return CrafterCraftEvent to host\");","typeGuard":"// host-side narrowing before calling from_wasm_event\nfn is_crafter_event(e: &Event) -> bool { matches!(e, Event::CrafterCraftEvent(_)) }","tryCatchPattern":null,"preventionTips":["Treat host->plugin events as consume-only; use cancellation/mutation APIs, not returns.","Regenerate bindings whenever the WIT version changes.","Review generated bindings' handler return types after SDK upgrades."],"tags":["wasm","plugin-host","panic","event-direction"],"backgroundTag":"unsupported-operation","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"}