jlcodes99/cockpit-tools · error

刷新 Codex 配额失败

Error message

刷新 Codex 配额失败

What it means

In src-tauri/src/commands/codex_account_commands.rs:1815 the refresh-Codex-quota Tauri command maps a failed inner refresh result to Err, falling back to the literal "刷新 Codex 配额失败" ("failed to refresh Codex quota") when the underlying error is somehow None. The frontend receives this as the command's rejection value; the actual cause is whatever the inner refresh produced.

Source

Thrown at src-tauri/src/commands/codex_account_commands.rs:1815

        return Ok(());
    }
    // 分组策略「不刷新」:自动当前号刷新静默跳过
    if !codex_account::is_quota_refresh_enabled_for_account(&account.id) {
        logger::log_info(&format!(
            "[Codex Quota] 当前账号所属分组已关闭额度刷新,跳过: account_id={}",
            account.id
        ));
        return Ok(());
    }

    let result = codex_quota::refresh_account_quota(&account.id).await;
    if result.is_ok() {
        run_codex_post_refresh_checks(&app).await;
        let _ = crate::modules::tray::update_tray_menu(&app);
        Ok(())
    } else {
        Err(result
            .err()
            .unwrap_or_else(|| "刷新 Codex 配额失败".to_string()))
    }
}

/// 刷新所有账号配额
#[tauri::command]
pub async fn refresh_all_codex_quotas(app: AppHandle) -> Result<i32, String> {
    let results = codex_quota::refresh_all_quotas().await?;
    let success_count = results.iter().filter(|(_, r)| r.is_ok()).count();
    if success_count > 0 {
        run_codex_post_refresh_checks(&app).await;
    }
    let _ = crate::modules::tray::update_tray_menu(&app);
    Ok(success_count as i32)
}

/// 按账号 ID 列表限流并发刷新配额(分组刷新 / 本地访问批量等)
/// 只在全部任务结束后做一次 tray / post-check,避免 N 次并发互踩。

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Re-authenticate the affected Codex account (re-run its login flow) to refresh the token, then retry quota refresh.
  2. Check network connectivity/proxy settings and retry; verify the quota endpoint is reachable.
  3. Read the full error string accompanying the message (the fallback literal means the real Err was lost) and log result.err() details upstream.
  4. If it persists, refresh all accounts via the '刷新所有账号配额' command or restart the app to rebuild account state.

Example fix

// before
Err(result.err().unwrap_or_else(|| "刷新 Codex 配额失败".to_string()))
// after
Err(result.err()
    .map(|e| format!("刷新 Codex 配额失败: {e}"))
    .unwrap_or_else(|| "刷新 Codex 配额失败: 未知原因".to_string()))
Defensive patterns

Strategy: try-catch

Validate before calling

// Frontend pre-check before refreshing quota:
const accounts = await invoke('list_codex_accounts');
if (!accounts.some(a => a.authenticated)) {
  console.warn('No authenticated Codex account; refresh will fail');
}

Type guard

function isRefreshResult(r: unknown): r is { ok: boolean; error?: string } {
  return typeof r === 'object' && r !== null && 'ok' in r;
}

Try / catch

try {
  await invoke('refresh_codex_quota', { accountId });
} catch (e) {
  console.error('刷新 Codex 配额失败:', e); // log full payload, not just the fallback literal
  await promptCodexReauth();
}

Prevention

When it happens

Trigger: The inner refresh routine returns Err (network failure reaching Codex quota endpoints, invalid/expired account token, backend returning non-success) — or returns Ok(false)-like empty Err — while refreshing a Codex account's quota from the UI.

Common situations: Codex auth token expired and needs re-login; offline or proxy/firewall blocking the quota API; Codex backend outage or rate limiting; stale account entry referencing a removed session.

Related errors


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