louis-e/arnis · info

glass color array is non-empty

Error message

glass color array is non-empty

What it means

`build_glass_item` selects a stained-glass color from the `GLASS_COLORS` constant via `GLASS_COLORS.choose(rng).expect("glass color array is non-empty")`. `choose` fails only on an empty slice, so this is a compile-time invariant assertion that should never trigger in normal operation.

Source

Thrown at src/element_processing/amenities.rs:855

        "blue",
        "brown",
        "green",
        "red",
        "black",
    ];

    let use_colorless = rng.random_bool(0.7);

    let id = if use_colorless {
        if is_pane {
            "minecraft:glass_pane".to_string()
        } else {
            "minecraft:glass".to_string()
        }
    } else {
        let color = GLASS_COLORS
            .choose(rng)
            .expect("glass color array is non-empty");
        if is_pane {
            format!("minecraft:{color}_stained_glass_pane")
        } else {
            format!("minecraft:{color}_stained_glass")
        }
    };

    let count = if is_pane {
        rng.random_range(4..=16)
    } else {
        rng.random_range(1..=6)
    };

    make_basic_item(&id, slot, count)
}

fn build_leather_item(piece: LeatherPiece, slot: i8, rng: &mut impl Rng) -> HashMap<String, Value> {
    let (id, max_damage) = match piece {

View on GitHub (pinned to 34048924d9)

Solutions

  1. Ensure `GLASS_COLORS` always contains at least one entry
  2. If the palette is configurable, validate it is non-empty before choosing and fall back to plain "minecraft:glass"
  3. Add a unit test asserting the palette is non-empty

Example fix

// before
let color = GLASS_COLORS.choose(rng).expect("glass color array is non-empty");
// after
let color = GLASS_COLORS.choose(rng).unwrap_or(&"white");
Defensive patterns

Strategy: validation

Validate before calling

assert!(!GLASS_COLORS.is_empty(), "glass color palette must not be empty");

Type guard

fn non_empty<T>(s: &[T]) -> bool { !s.is_empty() }

Prevention

When it happens

Trigger: Only when `GLASS_COLORS` is edited to an empty array or becomes a dynamically built collection that ends up empty at runtime.

Common situations: Refactoring the color palette or gating colors behind features that are all disabled; never in an unmodified build.

Related errors


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