louis-e/arnis · error

Invalid id

Error message

Invalid id

What it means

`BlockDescriptor::name()` is a convenience wrapper that calls `try_name()` and panics with "Invalid id" via `.expect()` when the block id has no assigned name. The library throws it because `try_name` only maps a fixed table of known ids to names, so any id outside that table (including unassigned/sentinel ids) has no name string to return.

Source

Thrown at src/block_definitions.rs:107

    #[inline(always)]
    pub const fn id(&self) -> u16 {
        self.id
    }

    /// Rebuild a block from a raw id, for the packed section storage.
    #[inline(always)]
    pub(crate) const fn from_raw_id(id: u16) -> Self {
        Self::new(id)
    }

    #[inline(always)]
    pub fn namespace(&self) -> &str {
        "minecraft"
    }

    pub fn name(&self) -> &str {
        self.try_name().expect("Invalid id")
    }

    /// Non-panicking variant of `name` (None for unassigned ids).
    pub fn try_name(&self) -> Option<&str> {
        Some(match self.id {
            0 => "mangrove_log",
            1 => "air",
            2 => "andesite",
            3 => "birch_leaves",
            4 => "birch_log",
            5 => "black_concrete",
            6 => "blackstone",
            7 => "blue_orchid",
            8 => "blue_terracotta",
            9 => "bricks",
            10 => "cauldron",
            11 => "chiseled_stone_bricks",
            12 => "cobblestone_wall",

View on GitHub (pinned to 34048924d9)

Solutions

  1. Before calling `name()`, call `try_name()` and handle the `None` case instead of unwrapping
  2. Validate the numeric id against the known id range/table before constructing or querying the block
  3. Trace the origin of the bad id (save file, network, default value) and fix the producer so only known ids flow in
  4. Update the library/world data if the id is valid in a newer version of the block table

Example fix

// before
let block_name = block.name();
// after
let block_name = block.try_name().unwrap_or("minecraft:air");
Defensive patterns

Strategy: validation

Validate before calling

let Some(name) = block.try_name() else { eprintln!("unknown block id {}", block.id()); return; };

Type guard

fn is_known_block(b: &BlockDescriptor) -> bool { b.try_name().is_some() }

Prevention

When it happens

Trigger: Calling `name()` on a block constructed with an id that is not in the `try_name` match table — e.g. an id read from an unrecognized save/chunk, an out-of-range numeric id, or an unassigned variant. It is hit anywhere `name()` is called: `to_bedrock_block`, `to_bedrock_block_with_properties`, `is_see_through`, `is_trunk`, `is_tree_part`.

Common situations: Loading a world file produced by a newer/older version with block ids this build does not know; parsing arbitrary numeric block ids from user input or external data; relying on the default/zero-value id of a struct instead of a real block.

Related errors


AI-assisted analysis of louis-e/arnis@34048924d9 (2026-09-03). Data as JSON: /api/errors/1b83fd58dbb6d7f7. Report an issue: GitHub.