{"record":{"id":"202d7237592b3555","repo":"tonhowtf/omniget","slug":"app-data-dir-unavailable","errorCode":null,"errorMessage":"app_data_dir unavailable","messagePattern":"app_data_dir unavailable","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/bilibili/cookie.rs","lineNumber":64,"sourceCode":"        crate::platforms::cookie_provider::cookie_path_for_account(\"bilibili.com\", ANONYMOUS_SLUG)?;\n    Some(cookie_path.with_file_name(\"_anonymous_meta.json\"))\n}\n\npub fn load_state() -> AnonymousCookieState {\n    let path = match meta_file_path() {\n        Some(p) => p,\n        None => return AnonymousCookieState::default(),\n    };\n    let content = match std::fs::read_to_string(&path) {\n        Ok(c) => c,\n        Err(_) => return AnonymousCookieState::default(),\n    };\n    serde_json::from_str(&content).unwrap_or_default()\n}\n\npub fn save_state(state: &AnonymousCookieState) -> std::io::Result<()> {\n    let path = meta_file_path().ok_or_else(|| {\n        std::io::Error::new(std::io::ErrorKind::Other, \"app_data_dir unavailable\")\n    })?;\n    if let Some(parent) = path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    let serialized = serde_json::to_string_pretty(state)\n        .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?;\n    std::fs::write(path, serialized)\n}\n\npub async fn ensure_fresh() -> Result<AnonymousCookieState> {\n    let cached = load_state();\n    if cached.is_fresh() {\n        write_netscape_for_anonymous(&cached).ok();\n        return Ok(cached);\n    }\n    bootstrap_anonymous().await\n}\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/bilibili/cookie.rs#L46-L82","documentation":"save_state persists bilibili anonymous cookie state by first resolving meta_file_path(), which is based on the app data directory. When the app data dir cannot be resolved it raises this io::Error (Kind::Other). Called from bootstrap_anonymous, this aborts anonymous-cookie bootstrapping since state cannot be written.","triggerScenarios":"Calling save_state (directly or via bootstrap_anonymous) on a system where the app data dir lookup returns None — e.g. Linux with HOME unset when computing the config/data dir, or a platform not supported by the dirs helper.","commonSituations":"Running the app in a container/service without HOME; first-run bootstrap in a headless environment; portable-style launches where the app-data resolution helper fails.","solutions":["Set HOME (Linux/macOS) so the app data dir can be resolved, then retry bootstrap_anonymous.","Ensure XDG_DATA_HOME/XDG_CONFIG_HOME are set if the paths helper uses them.","Wrap save_state failures in bootstrap_anonymous so bootstrapping degrades gracefully instead of hard-failing.","Run within a normal user session rather than a service account."],"exampleFix":"// service launch fix\nEnvironment=HOME=/home/omniget\nXDG_DATA_HOME=/home/omniget/.local/share\n# or in code\nlet state = AnonymousCookieState::default();\nsave_state(&state).map_err(|e| log::warn!(\"cookie state not saved: {e}\")).unwrap_or(());","handlingStrategy":"try-catch","validationCode":"let app_data_ok = std::env::var(\"HOME\").is_ok()\n    || std::env::var(\"XDG_DATA_HOME\").is_ok();\nif !app_data_ok { eprintln!(\"cannot resolve app data dir; set HOME\"); }","typeGuard":null,"tryCatchPattern":"match save_state(&state) {\n    Err(e) if e.to_string().contains(\"app_data_dir unavailable\") => {\n        log::warn!(\"skipping cookie persistence: {e}\"); // continue anonymous\n    }\n    Err(e) => return Err(e.into()),\n    Ok(()) => {}\n}","preventionTips":["Set HOME/XDG_DATA_HOME in service/container environments","Make bootstrap_anonymous tolerate persistence failure (cookies still work in-memory)","Run under a real user account so platform dir helpers resolve"],"tags":["bilibili","cookie","app-data-dir","paths"],"backgroundTag":"missing-env-var","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}