{"record":{"id":"2456ace61c2ad54a","repo":"a-b-street/abstreet","slug":"can-t-maybe-read-binary-it-doesn-t-exist","errorCode":null,"errorMessage":"Can't maybe_read_binary {}, it doesn't exist","messagePattern":"Can't maybe_read_binary (.+?), it doesn't exist","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"abstio/src/io_web.rs","lineNumber":114,"sourceCode":"            use base64::Engine;\n            let bytes = base64::engine::general_purpose::STANDARD.decode(string)?;\n            Ok(bytes)\n        }\n    } else {\n        bail!(\"Can't slurp_file {}, it doesn't exist\", path)\n    }\n}\n\npub fn maybe_read_binary<T: DeserializeOwned>(path: String, _: &mut Timer) -> Result<T> {\n    if let Some(raw) = SYSTEM_DATA.get_file(path.trim_start_matches(\"../data/system/\")) {\n        bincode::deserialize(raw.contents()).map_err(|err| err.into())\n    } else if path.starts_with(&path_player(\"\")) {\n        let string = read_local_storage(&path)?;\n        use base64::Engine;\n        let out = bincode::deserialize(&base64::engine::general_purpose::STANDARD.decode(string)?)?;\n        Ok(out)\n    } else {\n        bail!(\"Can't maybe_read_binary {}, it doesn't exist\", path)\n    }\n}\n\npub fn write_json<T: Serialize>(path: String, obj: &T) {\n    // Only save for data/player, for now\n    if !path.starts_with(&path_player(\"\")) {\n        warn!(\"Not saving {}\", path);\n        return;\n    }\n\n    let window = web_sys::window().unwrap();\n    let storage = window.local_storage().unwrap().unwrap();\n    storage.set_item(&path, &abstutil::to_json(obj)).unwrap();\n}\n\npub fn write_binary<T: Serialize>(path: String, obj: &T) {\n    write_raw(path, &abstutil::to_binary(obj)).unwrap();\n}","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/a-b-street/abstreet/blob/0964f29315820c91b171b585eb51e300164e9197/abstio/src/io_web.rs#L96-L132","documentation":"On web, abstio::maybe_read_binary deserializes bincode data either from the embedded SYSTEM_DATA archive (paths under ../data/system/) or from localStorage (paths under data/player/). If the path matches neither source, it bails with \"Can't maybe_read_binary ..., it doesn't exist\".","triggerScenarios":"Requesting a .bin system file not present in the web bundle; using a path that is neither system- nor player-prefixed; reading a player file that was never saved to localStorage.","commonSituations":"Fresh browser session where nothing was ever saved to localStorage; new binary data files not yet baked into the web build; mistyped or non-normalized paths.","solutions":["Verify the path starts with ../data/system/ or the player data prefix and that the file was included in the web build.","Provide a fallback/default value with maybe_read_binary when the item may legitimately not exist yet.","Rebuild the web bundle so new binary data is embedded."],"exampleFix":"// before\nlet map = abstio::maybe_read_binary::<Map>(map_path, timer).ok();\n// after\nlet map = abstio::maybe_read_binary::<Map>(map_path, timer)\n    .map_err(|_| anyhow!(\"map {} not embedded in web build\", map_path))?;","handlingStrategy":"fallback","validationCode":"let readable = path.starts_with(\"../data/system/\") || path.starts_with(&abstio::path_player(\"\"));","typeGuard":null,"tryCatchPattern":"let value = abstio::maybe_read_binary::<T>(path, timer).unwrap_or_else(|_| T::default());","preventionTips":["Only reference system- or player-prefixed paths on web.","Treat player-storage reads as optional — first runs have nothing saved.","Keep web builds in sync with new binary data files."],"tags":["web","wasm","bincode","file-not-found"],"backgroundTag":"file-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"}