{"record":{"id":"ecd58f8741276994","repo":"a-b-street/abstreet","slug":"0-dist-ahead-for-slice","errorCode":null,"errorMessage":"0 dist ahead for slice","messagePattern":"0 dist ahead for slice","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"map_model/src/pathfind/v1.rs","lineNumber":56,"sourceCode":"\n    pub fn as_turn(&self) -> TurnID {\n        self.as_traversable().as_turn()\n    }\n\n    // start is relative to the start of the actual geometry -- so from the lane's real start for\n    // ContraflowLane.\n    fn exact_slice(\n        &self,\n        map: &Map,\n        start: Distance,\n        dist_ahead: Option<Distance>,\n    ) -> Result<PolyLine> {\n        if let Some(d) = dist_ahead {\n            if d < Distance::ZERO {\n                panic!(\"Negative dist_ahead?! {}\", d);\n            }\n            if d == Distance::ZERO {\n                bail!(\"0 dist ahead for slice\");\n            }\n        }\n\n        match self {\n            PathStep::Lane(id) => {\n                let pts = &map.get_l(*id).lane_center_pts;\n                if let Some(d) = dist_ahead {\n                    pts.maybe_exact_slice(start, start + d)\n                } else {\n                    pts.maybe_exact_slice(start, pts.length())\n                }\n            }\n            PathStep::ContraflowLane(id) => {\n                let pts = map.get_l(*id).lane_center_pts.reversed();\n                let reversed_start = pts.length() - start;\n                if let Some(d) = dist_ahead {\n                    pts.maybe_exact_slice(reversed_start, reversed_start + d)\n                } else {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/map_model/src/pathfind/v1.rs#L38-L74","documentation":"PathV1::exact_slice slices a path step's polyline over a distance window. If dist_ahead is explicitly Some(0), there is no distance to slice, which the library treats as an error rather than returning an empty polyline. It guards callers from constructing degenerate PathV1 slices.","triggerScenarios":"Calling PathV1::exact_slice (or following a path step) with dist_ahead = Some(Distance::ZERO) — i.e. requesting a slice that starts exactly at the step's end with nothing ahead (map_model/src/pathfind/v1.rs:56).","commonSituations":"Simulation code computing \"remaining distance\" that hits exactly 0 at a step boundary; callers not filtering zero-length remainders before slicing.","solutions":["Skip the slice entirely when the remaining distance is zero (the step is fully consumed).","Use `if d > Distance::ZERO` guards before calling exact_slice.","Advance to the next PathStep instead of slicing the current one at zero length.","If zero slices should be legal, change the caller to pass None and handle the empty case explicitly."],"exampleFix":"// before\nlet slice = path.exact_slice(&map, dist_ahead)?; // dist_ahead may be 0\n// after\nif dist_ahead > Distance::ZERO {\n    let slice = path.exact_slice(&map, dist_ahead)?;\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn sliceable(d: Option<Distance>) -> bool {\n    matches!(d, None) || matches!(d, Some(x) if x > Distance::ZERO)\n}\n// if sliceable(dist_ahead) { path.exact_slice(&map, dist_ahead)?; }","tryCatchPattern":"match path.exact_slice(&map, dist_ahead) {\n    Err(e) if e.to_string() == \"0 dist ahead for slice\" => {\n        // step fully consumed: advance to next PathStep instead\n    }\n    other => other?,\n}","preventionTips":["Guard every exact_slice call with `if remaining > Distance::ZERO`.","Treat zero remaining distance as \"move to next step\", never as a slice.","Avoid accumulating distance with floating point that can leave tiny zero-length remainders at step boundaries."],"tags":["pathfinding","slicing","zero-distance","map-model"],"backgroundTag":"value-out-of-range","analyzedSha":"0964f29315820c91b171b585eb51e300164e9197","analyzedAt":"2026-09-13T18:02:03.421Z","contentChangedAt":"2026-09-13T18:02:03.421Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}