jlcodes99/cockpit-tools · error

读取文件失败

Error message

读取文件失败 {:?}: {}

What it means

File-read guard in import_from_files (codex account import): fs::read_to_string failed for one of the selected file paths — missing file, permission denied, or non-UTF8 content — formatted as '读取文件失败 {:?}: {}'. The error is logged and that file is skipped while the remaining selected files continue through the import candidates.

Solutions

  1. Check the reported path exists and is readable by the app
  2. Re-select the file via the picker instead of a stale recent-files path
  3. Convert non-UTF8 encodings before importing
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/cockpit-core/src/modules/codex_account_core_mutations_quota.rs:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/87f62ed52f013964. Report an issue: GitHub.

Appendix: source

Thrown at crates/cockpit-core/src/modules/codex_account_core_mutations_quota.rs:27

    }
    ensure_storage_writable_for_import()?;

    logger::log_info(&format!(
        "Codex: 开始从 {} 个文件导入账号...",
        file_paths.len()
    ));

    // 原有文件导入候选: (CodexTokens, account_id_hint, label)
    let mut candidates: Vec<(CodexTokens, Option<String>, String)> = Vec::new();
    // 旧规则未识别到账号时,才用 Token/JSON 粘贴框的解析逻辑处理整个文件内容。
    let mut fallback_files: Vec<(String, String)> = Vec::new();

    for file_path in &file_paths {
        let path = Path::new(file_path);
        let content = match fs::read_to_string(path) {
            Ok(c) => c,
            Err(e) => {
                logger::log_error(&format!("读取文件失败 {:?}: {}", file_path, e));
                continue;
            }
        };

        // 从文件名推断 email 作为 label
        let filename_label = path
            .file_stem()
            .and_then(|s| s.to_str())
            .unwrap_or("unknown")
            .to_string();

        let parsed: serde_json::Value = match serde_json::from_str(&content) {
            Ok(v) => v,
            Err(e) => {
                logger::log_warn(&format!(
                    "Codex 文件旧规则 JSON 解析失败,将尝试 Token/JSON 导入逻辑 {:?}: {}",
                    file_path, e
                ));

View on GitHub (pinned to 1ed8b77992)