a-b-street/abstreet · error

Not a CarID

Error message

Not a CarID: {:?}

What it means

Generic enum-variant unwrapping helper on AgentID: as_car asserts the agent is AgentID::Car and this panic fires when called on a Pedestrian or BusPassenger variant. The faulty input is the AgentID itself — the caller's routing logic sent a non-car agent to car-only code.

Solutions

  1. Match on AgentID explicitly or use to_type() to dispatch before calling as_car
  2. Fix the caller so only car agents reach this code path
  3. Return Option<CarID> from a new helper and handle non-car agents gracefully
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at sim/src/lib.rs:140 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of a-b-street/abstreet@0964f29315 (2026-09-13). Data as JSON: /api/errors/d2d9e7b9181c4a42. Report an issue: GitHub.

Appendix: source

Thrown at sim/src/lib.rs:140

impl AgentID {
    pub(crate) fn as_car(self) -> CarID {
        match self {
            AgentID::Car(id) => id,
            _ => panic!("Not a CarID: {:?}", self),
        }
    }

    pub fn to_type(self) -> AgentType {
        match self {
            AgentID::Car(c) => match c.vehicle_type {
                VehicleType::Car => AgentType::Car,
                VehicleType::Bike => AgentType::Bike,
                VehicleType::Bus => AgentType::Bus,
                VehicleType::Train => AgentType::Train,
            },
            AgentID::Pedestrian(_) => AgentType::Pedestrian,

View on GitHub (pinned to 0964f29315)