a-b-street/abstreet · error
PathConstraints::from_lt
Error message
PathConstraints::from_lt({:?}) doesn't make sense What it means
PathConstraints::from_lt converts a LaneType into the PathConstraints an agent needs to traverse it. The panic fires for LaneType variants that have no meaningful agent constraint mapping (e.g. construction or footway-only variants not listed in the match). It is an internal exhaustiveness guard: the library assumes every LaneType passed here is one of the six mappable variants.
Solutions
- Match only LaneTypes that map to a PathConstraints; filter or skip unmappable lanes before calling from_lt
- Check LaneType for the problematic lane in your map data and fix the input data or its tags
- Update the match arm in PathConstraints::from_lt to map the new LaneType to a sensible constraint
- Use PathConstraints::from_lt only on lane types you have validated, handling the catch-all case yourself
Example fix
// before
let constraints = PathConstraints::from_lt(lane.lt);
// after
let constraints = match lane.lt {
LaneType::Sidewalk | LaneType::Shoulder | LaneType::Footway => PathConstraints::Pedestrian,
LaneType::Driving => PathConstraints::Car,
LaneType::Biking => PathConstraints::Bike,
LaneType::Bus => PathConstraints::Bus,
LaneType::LightRail => PathConstraints::Train,
other => { eprintln!("skipping unmappable lane type {:?}", other); continue; }
}; Defensive patterns
Strategy: validation
Validate before calling
fn is_mappable(lt: LaneType) -> bool {
matches!(lt, LaneType::Sidewalk | LaneType::Shoulder | LaneType::Driving | LaneType::Biking | LaneType::Bus | LaneType::LightRail)
} Type guard
fn to_constraints(lt: LaneType) -> Option<PathConstraints> {
match lt {
LaneType::Sidewalk | LaneType::Shoulder => Some(PathConstraints::Pedestrian),
LaneType::Driving => Some(PathConstraints::Car),
LaneType::Biking => Some(PathConstraints::Bike),
LaneType::Bus => Some(PathConstraints::Bus),
LaneType::LightRail => Some(PathConstraints::Train),
_ => None,
}
} Prevention
- Use an Option-returning wrapper instead of the panicking from_lt for untrusted lane types
- Keep the LaneType match in sync whenever new LaneType variants are introduced
- Validate map input data lane types before pathfinding
- Add a test iterating all LaneType variants against from_lt
When it happens
Trigger: Calling from_lt (directly or via pathfinding setup that classifies lanes) with a LaneType value outside {Sidewalk, Shoulder, Driving, Biking, Bus, LightRail}, such as LaneType::Construction or other map data lane types.
Common situations: Loading map data with unusual OSM lane types and then building pathfinding routes for them; a new LaneType variant added upstream without updating this match; calling from_lt in custom tooling over all lanes in a map.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Negative dist_ahead?!
- expected turn, but found
- modify_step broke total_length, it's now
- Empty path
- pathfind() returned path that warps
AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13).
Data as JSON: /api/errors/da31c10c24c6f312.
Report an issue: GitHub.
Appendix: source
Thrown at map_model/src/pathfind/mod.rs:58
pub fn all() -> Vec<PathConstraints> {
vec![
PathConstraints::Pedestrian,
PathConstraints::Car,
PathConstraints::Bike,
PathConstraints::Bus,
PathConstraints::Train,
]
}
/// Not bijective, but this is the best guess of user intent
pub fn from_lt(lt: LaneType) -> PathConstraints {
match lt {
LaneType::Sidewalk | LaneType::Shoulder => PathConstraints::Pedestrian,
LaneType::Driving => PathConstraints::Car,
LaneType::Biking => PathConstraints::Bike,
LaneType::Bus => PathConstraints::Bus,
LaneType::LightRail => PathConstraints::Train,
_ => panic!("PathConstraints::from_lt({:?}) doesn't make sense", lt),
}
}
/// Can an agent use a lane? There are some subtle exceptions with using bus-only lanes for
/// turns.
pub fn can_use(self, lane: &Lane, map: &Map) -> bool {
let result = match self {
PathConstraints::Pedestrian => {
return lane.is_walkable();
}
PathConstraints::Car => lane.is_driving(),
PathConstraints::Bike => {
if lane.is_biking() {
true
} else if lane.is_driving() || (lane.is_bus() && map.config.bikes_can_use_bus_lanes)
{
let road = map.get_r(lane.id.road);
!road.osm_tags.is("bicycle", "no")View on GitHub (pinned to 0964f29315)