{"record":{"id":"f86f41344843b931","repo":"a-b-street/abstreet","slug":"can-t-find-the-data-directory","errorCode":null,"errorMessage":"Can't find the data/ directory","messagePattern":"Can't find the data/ directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"abstio/src/abst_paths.rs","lineNumber":41,"sourceCode":"            // If you're packaging for a release and want the player's local data directory to be\n            // $HOME/.abstreet, set ABST_PLAYER_HOME_DIR=1\n            if option_env!(\"ABST_PLAYER_HOME_DIR\").is_some() {\n                match std::env::var(\"HOME\") {\n                    Ok(dir) => format!(\"{}/.abstreet\", dir.trim_end_matches('/')),\n                    Err(err) => panic!(\"This build of A/B Street stores player data in $HOME/.abstreet, but $HOME isn't set: {}\", err),\n                }\n            } else if cfg!(target_arch = \"wasm32\") {\n                \"../data\".to_string()\n            } else if file_exists(\"data/\".to_string()) {\n                \"data\".to_string()\n            } else if file_exists(\"../data/\".to_string()) {\n                \"../data\".to_string()\n            } else if file_exists(\"../../data/\".to_string()) {\n                \"../../data\".to_string()\n            } else if file_exists(\"../../../data/\".to_string()) {\n                \"../../../data\".to_string()\n            } else {\n                panic!(\"Can't find the data/ directory\");\n            }\n        });\n        format!(\"{dir}/{p}\")\n    } else {\n        let dir = ROOT_DIR.get_or_init(|| {\n            // If you're packaging for a release and need the data directory to be in some fixed\n            // location: ABST_DATA_DIR=/some/path cargo build ...\n            if let Some(dir) = option_env!(\"ABST_DATA_DIR\") {\n                dir.trim_end_matches('/').to_string()\n            } else if cfg!(target_arch = \"wasm32\") {\n                \"../data\".to_string()\n            } else if file_exists(\"data/\".to_string()) {\n                \"data\".to_string()\n            } else if file_exists(\"../data/\".to_string()) {\n                \"../data\".to_string()\n            } else if file_exists(\"../../data/\".to_string()) {\n                \"../../data\".to_string()\n            } else if file_exists(\"../../../data/\".to_string()) {","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/abstio/src/abst_paths.rs#L23-L59","documentation":"abstio::path resolves non-player paths by locating the repo's data/ directory: it checks ABST_DATA_DIR (compile time), wasm, then data/, ../data/, ../../data/, ../../../data/ relative to the current working directory. If none of these exists when the path root is first initialized, it panics with 'Can't find the data/ directory'. This is the player/-branch variant (ROOT_PLAYER_DIR), i.e. it fires while resolving a 'player/...' path.","triggerScenarios":"First call to abstio::path (or path_player/path_edits/path_save etc.) with a 'player/'-prefixed path, from a working directory where none of data/, ../data/, ../../data/, ../../../data/ exists and the binary was not compiled with ABST_DATA_DIR set (or not on wasm32). The OnceLock caches the failure on the first call.","commonSituations":"Running a compiled A/B Street binary outside the repository checkout (e.g. copying the executable elsewhere), running tests/crates from a directory above or beside the repo, CI jobs that don't clone data/, or builds without ABST_DATA_DIR set while packaged.","solutions":["Run the binary from a directory where data/ exists (the repo root) or within 3 levels of it (so ../data, ../../data, or ../../../data resolves)","Rebuild with ABST_DATA_DIR set to the absolute path of the data directory: ABST_DATA_DIR=/path/to/abstreet/data cargo build --release","Clone/sync the data directory (e.g. ./import.sh or downloading data from the project) next to where the binary runs","Patch ROOT_PLAYER_DIR resolution to accept an explicit runtime override (env var read at runtime instead of option_env!)"],"exampleFix":"// before\n./target/release/abstreet   # run from ~/, no data/ nearby -> panic\n// after\ncd /path/to/abstreet && ./target/release/abstreet\n# or: ABST_DATA_DIR=/path/to/abstreet/data cargo build --release","handlingStrategy":"validation","validationCode":"fn data_dir_locatable() -> bool {\n    [\"data/\", \"../data/\", \"../../data/\", \"../../../data/\"]\n        .iter()\n        .any(|p| std::path::Path::new(p).is_dir())\n        || std::env::var_os(\"ABST_DATA_DIR\").is_some()\n}","typeGuard":"fn can_resolve_abstio_paths() -> bool {\n    cfg!(target_arch = \"wasm32\")\n        || std::env::var_os(\"ABST_DATA_DIR\").is_some()\n        || data_dir_locatable()\n}","tryCatchPattern":"let ok = std::panic::catch_unwind(|| abstio::path(\"system/us/seattle/maps/montlake.bin\"));\nif ok.is_err() {\n    eprintln!(\"Run from the repo root (or set ABST_DATA_DIR at build time)\");\n}","preventionTips":["Run A/B Street binaries and tests from the repository root or within 3 levels of it","Keep the data/ directory next to where you execute the binary","Set ABST_DATA_DIR at build time for fixed-location installs","Check that data/ exists in CI before invoking tools that use abstio::path"],"tags":["rust","panic","missing-directory","working-directory","data-directory"],"backgroundTag":"directory-not-found","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"}