louis-e/arnis · error
internal error: entered unreachable code
Error message
internal error: entered unreachable code
What it means
In `generate_leisure`, a `random_choice` value is matched against ranges 0..5, 5..10, 10..16, 16..22, 22..30 to pick a flower/fern block, with `_ => unreachable!()`. The panic means the code produced a `random_choice` outside 0..30, i.e. the value generator and this match table are out of sync (note 0..5/5..10 are exclusive ranges, so 5 and 10 fall through correctly to later arms, but anything >= 30 does not).
Source
Thrown at src/element_processing/leisure.rs:117
// or path inside the park is drawn after it, so its columns still
// read as grass here and only the mask tells them apart.
if matches!(leisure_type.as_str(), "park" | "garden" | "nature_reserve")
&& editor.check_for_block(x, 0, z, Some(&[GRASS_BLOCK]))
&& !editor.surface_is_sealed(x, z)
&& !editor.is_lc_water(x, z)
{
let random_choice: i32 = rng.random_range(0..1000);
match random_choice {
0..30 => {
// Plants
let plant_choice = match random_choice {
0..5 => RED_FLOWER,
5..10 => YELLOW_FLOWER,
10..16 => BLUE_FLOWER,
16..22 => WHITE_FLOWER,
22..30 => FERN,
_ => unreachable!(),
};
editor.set_block(plant_choice, x, 1, z, None, None);
}
30..90 => {
// Grass
editor.set_block(GRASS, x, 1, z, None, None);
}
90..105 => {
// Oak leaves
editor.set_block(OAK_LEAVES, x, 1, z, None, None);
}
105..120 => {
// Only where land cover says woody, else a park
// canopies its own meadows. 1/1000 for specimens.
if random_choice == 105 || editor.land_cover_backs_trees(x, z) {
Tree::create(
editor,
(x, 1, z),View on GitHub (pinned to 34048924d9)
Solutions
- Find where `random_choice` is generated and make its range exactly 0..30 to match the arms
- Replace `unreachable!()` with a fallback arm (`_ => FERN`) so out-of-range values degrade gracefully
- Align both the generator range and the match arms in one commit and add a debug_assert for the bound
Example fix
// before _ => unreachable!(), // after _ => FERN, // safe fallback for any out-of-range value // and upstream: rng.random_range(0..30)
Defensive patterns
Strategy: fallback
Validate before calling
debug_assert!((0..30).contains(&random_choice), "random_choice {random_choice} outside plant table 0..30"); Type guard
fn in_plant_range(v: i32) -> bool { (0..30).contains(&v) } Prevention
- Keep the RNG range and match arms in one constant (e.g. PLANT_TABLE_LEN)
- Use a catch-all arm returning a default block
- Add a test iterating the full generator range through the match
When it happens
Trigger: `random_choice` is generated with a range wider than 0..30 upstream (e.g. `rng.random_range(0..100)` or an inclusive upper bound), or the match arms were narrowed without updating the generator.
Common situations: Refactoring the plant distribution tables; changing the RNG range in one place but not the other; copy-pasting a similar match from another generator with different bounds.
Related errors
- Failed to create tile XZBBox
- internal error: entered unreachable code
- provider chain is never empty
- Earth has no PDS raster
- Invalid id
AI-assisted analysis of louis-e/arnis@34048924d9 (2026-09-03).
Data as JSON: /api/errors/6eb0ef25faae2630.
Report an issue: GitHub.