{"record":{"id":"e4587d682d596adf","repo":"louis-e/arnis","slug":"internal-error-entered-unreachable-code-e4587d","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/element_processing/tree.rs","lineNumber":477,"sourceCode":"    /// The species mix for a scattered tree, keyed on the column.\n    fn random_type(x: i32, z: i32) -> TreeType {\n        let mut rng = coord_rng(x, z, 0);\n        match rng.random_range(1..=100) {\n            1..=20 => TreeType::Oak,\n            21..=32 => TreeType::Spruce,\n            33..=44 => TreeType::Birch,\n            45..=50 => TreeType::DarkOak,\n            51..=56 => TreeType::Jungle,\n            57..=62 => TreeType::Acacia,\n            63..=64 => TreeType::Cherry,\n            65..=70 => TreeType::TallOak,\n            71..=77 => TreeType::Pine,\n            78..=84 => TreeType::Bush,\n            85..=88 => TreeType::AzaleaBush,\n            89..=92 => TreeType::Willow,\n            93..=98 => TreeType::FloweringOak,\n            99..=100 => TreeType::Mangrove,\n            _ => unreachable!(),\n        }\n    }\n\n    /// Creates a tree at the specified coordinates.\n    pub fn create(\n        editor: &mut WorldEditor,\n        (x, y, z): Coord,\n        building_footprints: Option<&BuildingFootprintBitmap>,\n        bridge_surface: Option<&BridgeSurfaceMap>,\n    ) {\n        let tree_type = Self::random_type(x, z);\n        Self::build(\n            editor,\n            (x, y, z),\n            tree_type,\n            building_footprints,\n            bridge_surface,\n            false,","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/louis-e/arnis/blob/34048924d9365795fb0d832e76140a3fbdc413d9/src/element_processing/tree.rs#L459-L495","documentation":"`Tree::random_type` maps a random number to a `TreeType` across arms like 71..=77 => Pine, ..., 99..=100 => Mangrove, with `_ => unreachable!()`. The panic fires when the random source yields a value outside the covered range (1..=100 here), meaning the RNG call and the match table disagree.","triggerScenarios":"The RNG range used to produce the value was changed (e.g. `random_range(0..=100)`, which includes 0 if arms start at 1, or a wider range), or an arm was removed/renumbered leaving a gap such as exclusive `99..100` vs inclusive `99..=100`.","commonSituations":"Refactoring the tree-type distribution; switching RNG providers with different range semantics (inclusive vs exclusive upper bounds); copy-pasted match tables drifting apart.","solutions":["Check the generator call and make its range exactly cover the arms (e.g. 1..=100)","Add a catch-all arm returning a default `TreeType` (e.g. Oak) instead of `unreachable!()`","Add a debug_assert/unit test that all values in the generator range are covered"],"exampleFix":"// before\n_ => unreachable!(),\n// after\n_ => TreeType::Oak,\n// upstream: let n = rng.random_range(1..=100);","handlingStrategy":"fallback","validationCode":"debug_assert!((1..=100).contains(&n), \"tree roll {n} outside 1..=100\");","typeGuard":"fn valid_tree_roll(n: i32) -> bool { (1..=100).contains(&n) }","tryCatchPattern":null,"preventionTips":["Define TREE_ROLL_RANGE constant used by both the RNG call and the arms","Mind inclusive vs exclusive Rust ranges (..= vs ..)","Default arm returning TreeType::Oak instead of unreachable!()"],"tags":["panic","unreachable","tree-generation"],"backgroundTag":"unreachable-arm-reached","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"}