{"record":{"id":"b4ded31fc1180f71","repo":"Pumpkin-MC/Pumpkin","slug":"failed-to-add-item-stack-resource","errorCode":null,"errorMessage":"failed to add item stack resource","messagePattern":"failed to add item stack resource","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/block.rs","lineNumber":990,"sourceCode":"\n    fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {\n        match event {\n            Event::BlockReceiveGameEvent(_) => {\n                panic!(\"Cannot construct BlockReceiveGameEvent from WASM\")\n            }\n            _ => panic!(\"unexpected event type\"),\n        }\n    }\n}\n\nimpl ToFromWasmEvent for BlockShearEntityEvent {\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        let item = state\n            .add_item_stack(Arc::new(Mutex::new(self.item.clone())))\n            .expect(\"failed to add item stack resource\");\n        Event::BlockShearEntityEvent(BlockShearEntityEventData {\n            block_pos: to_wasm_block_position(self.block_pos),\n            target_world,\n            target_entity_id: self.target.get_entity().entity_id,\n            item,\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::BlockShearEntityEvent(data) = event {\n            self.cancelled = data.cancelled;\n        }\n    }\n\n    fn from_wasm_event(event: Event, _state: &mut PluginHostState) -> Self {\n        match event {","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin/src/plugin/loader/wasm/wasm_host/wit/v0_1/events/block.rs#L972-L1008","documentation":"In to_wasm_event for BlockShearEntityEvent, after registering the world, the sheared item's ItemStack is wrapped in Arc<Mutex<>> and registered via state.add_item_stack(...); failure is unwrapped with expect('failed to add item stack resource'), panicking if the stack resource cannot be added to the host's resource table.","triggerScenarios":"Dispatching BlockShearEntityEvent to a WASM plugin when add_item_stack fails: resource-table exhaustion, invalid PluginHostState, or host shutdown in progress.","commonSituations":"High event volume filling the resource table; item stack added but never consumed after cancelled events; dispatch during plugin reload while state is reset.","solutions":["Ensure item stack resources are consumed/freed after each event so the resource table doesn't exhaust.","Verify PluginHostState is alive and current before dispatching block shear events.","Convert the expect into error propagation so dispatch can skip the plugin instead of panicking.","Check for double-registration of the same stack and reuse resource handles where supported."],"exampleFix":"// before\nlet item = state\n    .add_item_stack(Arc::new(Mutex::new(self.item.clone())))\n    .expect(\"failed to add item stack resource\");\n// after\nlet item = match state.add_item_stack(Arc::new(Mutex::new(self.item.clone()))) {\n    Ok(item) => item,\n    Err(e) => {\n        log::error!(\"failed to add item stack resource: {e}\");\n        return;\n    }\n};","handlingStrategy":"validation","validationCode":"// Confirm state capacity before registering the item stack\nif state.resource_count() >= state.resource_limit() {\n    log::warn!(\"plugin host resource table full; skipping event\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| dispatch_event(event))).unwrap_or_else(|_| {\n    log::error!(\"failed to add item stack resource during event dispatch\");\n});","preventionTips":["Always let the host consume item-stack resources after the plugin returns so they don't leak.","Watch resource-table growth under high shear/shear-like event volume and recycle hosts proactively.","Verify PluginHostState validity before each dispatch during plugin reloads.","Replace the expect with error handling when patching the host so dispatch can skip cleanly."],"tags":["wasm","plugin-host","panic","resource-registration","itemstack"],"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"}