{"record":{"id":"761012b05217a8e6","repo":"jlcodes99/cockpit-tools","slug":"error-761012","errorCode":null,"errorMessage":"无法获取用户目录","messagePattern":"无法获取用户目录","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/cockpit-core/src/modules/codex_account_core_tokens.rs","lineNumber":7,"sourceCode":"// cockpit-core Codex 账号：Token identity, refresh state, account index and lifecycle。\n// 通过 include! 保持原模块作用域和凭据调用路径。\n/// 获取我们的多账号存储路径（统一使用 ~/.antigravity_cockpit/）\nfn get_accounts_storage_path() -> PathBuf {\n    let data_dir = account::get_data_dir().unwrap_or_else(|_| {\n        dirs::home_dir()\n            .expect(\"无法获取用户目录\")\n            .join(\".antigravity_cockpit\")\n    });\n    fs::create_dir_all(&data_dir).ok();\n    migrate_codex_data_if_needed(&data_dir);\n    data_dir.join(\"codex_accounts.json\")\n}\n\n/// 获取账号详情存储目录（统一使用 ~/.antigravity_cockpit/codex_accounts/）\nfn get_accounts_dir() -> PathBuf {\n    let data_dir = account::get_data_dir().unwrap_or_else(|_| {\n        dirs::home_dir()\n            .expect(\"无法获取用户目录\")\n            .join(\".antigravity_cockpit\")\n    });\n    let accounts_dir = data_dir.join(\"codex_accounts\");\n    fs::create_dir_all(&accounts_dir).ok();\n    accounts_dir\n}","sourceCodeStart":1,"sourceCodeEnd":25,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/crates/cockpit-core/src/modules/codex_account_core_tokens.rs#L1-L25","documentation":"get_accounts_storage_path builds the multi-account index path under ~/.antigravity_cockpit/. When account::get_data_dir() returns None it falls back to dirs::home_dir().expect(\"无法获取用户目录\"), panicking if the OS home directory cannot be resolved. Returns the codex_accounts.json index path.","triggerScenarios":"Calling get_accounts_storage_path (via load_account_index, save_account_index, ensure_storage_writable_for_import, etc.) when get_data_dir() yields None and dirs::home_dir() is None — no resolvable home directory.","commonSituations":"CI/test runs without HOME set (note test_env_guard_isolates_and_restores_cockpit_data_dir is a listed caller); service accounts without user profiles; containers with minimal env.","solutions":["Set HOME (Unix) or USERPROFILE (Windows) to a writable directory before running.","Configure the data-dir override that account::get_data_dir() honors so the home fallback is never taken.","Pre-check the environment and fail fast with a clear message instead of letting the panic surface mid-operation.","Run import/index operations only in a proper user session."],"exampleFix":"// before\nlet path = get_accounts_storage_path(); // panics if no home\n\n// after\nif std::env::var_os(\"HOME\").is_none()\n    && std::env::var_os(\"USERPROFILE\").is_none()\n{\n    anyhow::bail!(\"home directory not set; cannot resolve account storage\");\n}\nlet path = get_accounts_storage_path();","handlingStrategy":"validation","validationCode":"fn account_storage_env_ok() -> bool {\n    std::env::var_os(\"HOME\").is_some() || std::env::var_os(\"USERPROFILE\").is_some()\n}","typeGuard":null,"tryCatchPattern":"std::panic::catch_unwind(get_accounts_storage_path).map_err(|_| anyhow::anyhow!(\"无法获取用户目录\"))","preventionTips":["Ensure HOME/USERPROFILE is exported in cron, systemd, and CI contexts","Configure the supported data-dir override so the home fallback never triggers","Pre-check the environment before account index load/save operations","Add an Env=HOME line to service unit definitions"],"tags":["panic","home-directory","storage","environment"],"backgroundTag":"missing-home-directory","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}