JuliusBrussee/caveman · error · Error

caveman: remote gateway key revocation failed

Error message

caveman: remote gateway key revocation failed (HTTP ${response.status}); credentials kept — retry `caveman logout`

What it means

Thrown during `caveman logout` when the remote gateway key revocation endpoint returns a non-2xx status that is not the tolerated 404 `cave_key_not_found` case. Local credentials are kept so logout can be retried safely.

Solutions

  1. Read the HTTP status in the message; for 401, re-authenticate (`caveman login`) then retry logout.
  2. Retry `caveman logout` after the gateway recovers (5xx) or the rate limit resets (429).
  3. If the server 404s with a different error code shape, verify gateway API version compatibility.
  4. Credentials are kept locally, so a simple retry is always safe.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await logout();
} catch (e) {
  if (e instanceof Error) {
    const m = e.message.match(/revocation failed \(HTTP (\d+)\)/);
    if (m && m[1] === "401") console.error("Token already invalid; login again before retrying logout.");
    else if (m && (m[1] === "503" || m[1] === "429")) console.error("Gateway temporarily failing/rate-limited; retry logout later.");
    else throw e;
  }
}

Prevention

When it happens

Trigger: `caveman logout` while the revocation endpoint responds 401 (expired/invalid token), 403, 500, 429 etc. — any failure status except 404 with error code `cave_key_not_found`.

Common situations: Access token expired before logout; gateway returning 5xx during an incident; rate limiting (429); revoked key via another device but server returning a different 404 body shape.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/b0e5937619ad2be2. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:9815

	const cfg = await config();
	const externalToken = Boolean(process.env.CAVE_TOKEN);
	if (cfg.token && (!cfg.logoutPendingLocalCleanup || externalToken)) {
	  if (cfg.projectId && cfg.gatewayKeyId) {
	    let response: Response;
	    try {
	      response = await fetch(`${cfg.baseURL}/api/v1/projects/${encodeURIComponent(cfg.projectId)}/keys/${encodeURIComponent(cfg.gatewayKeyId)}/revoke`, {
	        method: "POST",
	        headers: { authorization: `Bearer ${cfg.token}`, "content-type": "application/json", "x-cave-csrf": "cli" },
	        body: "{}",
	        signal: AbortSignal.timeout(5000),
	      });
	    } catch {
	      throw new Error("caveman: remote gateway key revocation was unavailable; credentials kept — retry `caveman logout`");
	    }
	    if (!response.ok) {
	      const body = await response.json().catch(() => null) as { error?: { code?: unknown } } | null;
	      const alreadyRevoked = response.status === 404 && body?.error?.code === "cave_key_not_found";
	      if (!alreadyRevoked) throw new Error(`caveman: remote gateway key revocation failed (HTTP ${response.status}); credentials kept — retry \`caveman logout\``);
	    }
	  }
	  const headers: Record<string, string> = {
	    authorization: `Bearer ${cfg.token}`,
	    "x-cave-client": "cli",
	  };
	  const request: RequestInit = {
	    method: "POST",
	    redirect: "manual",
	    headers,
	    signal: AbortSignal.timeout(5000),
	  };
	  if (cfg.refreshToken) {
	    headers["content-type"] = "application/json";
	    request.body = JSON.stringify({ refresh_token: cfg.refreshToken });
	  }
	  let response: Response;
	  try {

View on GitHub (pinned to 3ee70a1026)