{"record":{"id":"4f7deff186a8e03c","repo":"louis-e/arnis","slug":"glass-color-array-is-non-empty","errorCode":null,"errorMessage":"glass color array is non-empty","messagePattern":"glass color array is non-empty","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/element_processing/amenities.rs","lineNumber":855,"sourceCode":"        \"blue\",\n        \"brown\",\n        \"green\",\n        \"red\",\n        \"black\",\n    ];\n\n    let use_colorless = rng.random_bool(0.7);\n\n    let id = if use_colorless {\n        if is_pane {\n            \"minecraft:glass_pane\".to_string()\n        } else {\n            \"minecraft:glass\".to_string()\n        }\n    } else {\n        let color = GLASS_COLORS\n            .choose(rng)\n            .expect(\"glass color array is non-empty\");\n        if is_pane {\n            format!(\"minecraft:{color}_stained_glass_pane\")\n        } else {\n            format!(\"minecraft:{color}_stained_glass\")\n        }\n    };\n\n    let count = if is_pane {\n        rng.random_range(4..=16)\n    } else {\n        rng.random_range(1..=6)\n    };\n\n    make_basic_item(&id, slot, count)\n}\n\nfn build_leather_item(piece: LeatherPiece, slot: i8, rng: &mut impl Rng) -> HashMap<String, Value> {\n    let (id, max_damage) = match piece {","sourceCodeStart":837,"sourceCodeEnd":873,"githubUrl":"https://github.com/louis-e/arnis/blob/34048924d9365795fb0d832e76140a3fbdc413d9/src/element_processing/amenities.rs#L837-L873","documentation":"`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.","triggerScenarios":"Only when `GLASS_COLORS` is edited to an empty array or becomes a dynamically built collection that ends up empty at runtime.","commonSituations":"Refactoring the color palette or gating colors behind features that are all disabled; never in an unmodified build.","solutions":["Ensure `GLASS_COLORS` always contains at least one entry","If the palette is configurable, validate it is non-empty before choosing and fall back to plain \"minecraft:glass\"","Add a unit test asserting the palette is non-empty"],"exampleFix":"// before\nlet color = GLASS_COLORS.choose(rng).expect(\"glass color array is non-empty\");\n// after\nlet color = GLASS_COLORS.choose(rng).unwrap_or(&\"white\");","handlingStrategy":"validation","validationCode":"assert!(!GLASS_COLORS.is_empty(), \"glass color palette must not be empty\");","typeGuard":"fn non_empty<T>(s: &[T]) -> bool { !s.is_empty() }","tryCatchPattern":null,"preventionTips":["Keep at least one default color in every palette","Add a unit test asserting non-empty palettes when adding new palettes"],"tags":["panic","invariant","item-generation"],"backgroundTag":"empty-collection-unwrap","analyzedSha":"34048924d9365795fb0d832e76140a3fbdc413d9","analyzedAt":"2026-09-03T14:05:17.283Z","contentChangedAt":"2026-09-03T14:05:17.283Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}