{"record":{"id":"aafcfd69f5a23ff9","repo":"a-b-street/abstreet","slug":"you-forgot-to-call-initialize-on-simflags-after-parsing-from","errorCode":null,"errorMessage":"You forgot to call initialize on SimFlags after parsing from structopt","messagePattern":"You forgot to call initialize on SimFlags after parsing from structopt","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sim/src/make/load.rs","lineNumber":75,"sourceCode":"    // TODO rename seattle_test\n    pub fn for_test(run_name: &str) -> SimFlags {\n        SimFlags {\n            load_path: None,\n            load: MapName::seattle(\"montlake\").path(),\n            scenario_modifiers: Vec::new(),\n            rng_seed: SimFlags::RNG_SEED,\n            opts: SimOptions::new(run_name),\n        }\n    }\n\n    pub fn make_rng(&self) -> XorShiftRng {\n        XorShiftRng::seed_from_u64(self.rng_seed)\n    }\n\n    /// Loads a map and simulation. Not appropriate for use in the UI or on web.\n    pub fn load_synchronously(&self, timer: &mut abstutil::Timer) -> (Map, Sim, XorShiftRng) {\n        if self.load.is_empty() {\n            panic!(\"You forgot to call initialize on SimFlags after parsing from structopt\");\n        }\n\n        let mut rng = self.make_rng();\n\n        let mut opts = self.opts.clone();\n\n        if self.load.starts_with(&abstio::path_player(\"saves/\")) {\n            info!(\"Resuming from {}\", self.load);\n\n            let sim: Sim = abstio::must_read_object(self.load.clone(), timer);\n\n            let mut map = Map::load_synchronously(sim.map_name.path(), timer);\n            match MapEdits::load_from_file(\n                &map,\n                abstio::path_edits(map.get_name(), &sim.edits_name),\n                timer,\n            ) {\n                Ok(edits) => {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/sim/src/make/load.rs#L57-L93","documentation":"SimFlags::load_synchronously requires the `load` field (what map/scenario/save to load) to be non-empty. Structopt/CLI parsing cannot infer this value, so SimFlags::initialize must be called first to fill it; loading with an empty path is treated as programmer error and panics.","triggerScenarios":"Constructing SimFlags via structopt/Defaults and calling load_synchronously() without first invoking SimFlags::initialize (which populates `load` from the map name).","commonSituations":"Headless/binary tools and tests that build SimFlags manually and skip initialize; copy-pasted flag setup where the initialize call was dropped; web/UI code paths that never call this headless loader.","solutions":["Call sim_flags.initialize(map_name) before load_synchronously","Verify the CLI actually carries a --load value when not using defaults","Use the intended UI loading path (SimFlags loading in map_gui) instead of the headless one"],"exampleFix":"// before\nlet flags = SimFlags::from_args();\nflags.load_synchronously(&mut timer);\n// after\nlet mut flags = SimFlags::from_args();\nflags.initialize(map_name);\nflags.load_synchronously(&mut timer);","handlingStrategy":"validation","validationCode":"if flags.load.is_empty() {\n    flags.initialize(map_name);\n}\nflags.load_synchronously(&mut timer);","typeGuard":"fn flags_ready(flags: &SimFlags) -> bool { !flags.load.is_empty() }","tryCatchPattern":"let result = std::panic::catch_unwind(|| flags.load_synchronously(&mut timer));","preventionTips":["Always call SimFlags::initialize right after constructing SimFlags from CLI args","Assert !load.is_empty() at the start of headless tools"],"tags":["rust","panic","missing-required-argument","cli"],"backgroundTag":"missing-required-config-field","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"}