Pumpkin-MC/Pumpkin · warning · InventoryError
Invalid slot
Error message
Invalid slot
What it means
InventoryError::InvalidSlot indicates the specified slot index is invalid or out of bounds for the target inventory. The library uses it to safely reject slot references that do not exist rather than panicking on an array index.
Solutions
- Validate the slot index against the inventory size before calling slot APIs
- Convert protocol (window) slot numbers to internal inventory indices via the container's slot mapping before use
- Silently ignore or log-and-discard invalid slot packets from clients instead of propagating the error
- Check for off-by-one errors after inventory size changes
Example fix
// before
let item = inventory.slot(packet.slot)?;
// after
if packet.slot < 0 || packet.slot as usize >= inventory.size() {
log::warn!("client sent invalid slot {}", packet.slot);
return Ok(());
}
let item = inventory.slot(packet.slot as usize)?; Defensive patterns
Strategy: validation
Validate before calling
fn slot_is_valid(slot: i32, size: usize) -> bool {
slot >= 0 && (slot as usize) < size
} Type guard
fn valid_slot(slot: i32, inv: &dyn Inventory) -> Option<usize> {
if slot >= 0 && (slot as usize) < inv.size() { Some(slot as usize) } else { None }
} Try / catch
match container.handle_click(player_id, click) {
Err(InventoryError::InvalidSlot) => {
log::warn!("invalid slot in packet from {player_id}; ignoring");
}
r => r?,
} Prevention
- Always bounds-check slot numbers from network packets against inventory size
- Convert window slot indices to internal indices via the container's slot mapping
- Re-check slot validity after any inventory resize or session change
- Ignore (don't propagate) invalid-slot packets coming from clients
When it happens
Trigger: Calling inventory get/set/interaction APIs with a slot index negative or >= the inventory size — e.g. malformed click packets with crafted slot numbers, or using a container-window slot index directly as an inventory-array index without converting through the slot mapping.
Common situations: Protocol clients sending out-of-range slot numbers in click/drag packets; hotbar vs container slot index confusion; inventory resized while a client still references old slot numbers.
Related errors
- Player ' ' tried to interact with a closed container
- Multiple players dragging in a container at once
- Out of order dragging
- JSON error
- Unable to lock
AI-assisted analysis of Pumpkin-MC/Pumpkin@8d4639e25a (2026-09-09).
Data as JSON: /api/errors/18adb54f1466c462.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pumpkin-inventory/src/error.rs:13
use thiserror::Error;
/// Errors that can occur during inventory operations.
///
/// These errors represent various failure conditions when handling inventory
/// interactions, such as invalid slot indices, permission issues, or protocol errors.
#[derive(Error, Debug)]
pub enum InventoryError {
/// Failed to acquire a lock on an inventory or slot.
#[error("Unable to lock")]
LockError,
/// The specified slot index is invalid or out of bounds.
#[error("Invalid slot")]
InvalidSlot,
/// A player attempted to interact with a container that is closed.
///
/// The parameter is the player's entity ID.
#[error("Player '{0}' tried to interact with a closed container")]
ClosedContainerInteract(i32),
/// Multiple players attempted to drag items in the same container simultaneously.
#[error("Multiple players dragging in a container at once")]
MultiplePlayersDragging,
/// Drag operation was performed out of order (e.g., end before start).
#[error("Out of order dragging")]
OutOfOrderDragging,
/// The received inventory packet is malformed or invalid.
#[error("Invalid inventory packet")]
InvalidPacket,
/// The player lacks permission to perform this inventory operation.
#[error("Player does not have enough permissions")]
PermissionError,View on GitHub (pinned to 8d4639e25a)