{"record":{"id":"65cf2675e8b9fb51","repo":"JuliusBrussee/caveman","slug":"caveman-remote-gateway-key-revocation-was-unavail","errorCode":null,"errorMessage":"caveman: remote gateway key revocation was unavailable; credentials kept — retry `caveman logout`","messagePattern":"caveman: remote gateway key revocation was unavailable; credentials kept — retry `caveman logout`","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9810,"sourceCode":"  }\n  throw new Error(\"device login timed out before approval\");\n}\n\nasync function logout() {\n\tconst cfg = await config();\n\tconst externalToken = Boolean(process.env.CAVE_TOKEN);\n\tif (cfg.token && (!cfg.logoutPendingLocalCleanup || externalToken)) {\n\t  if (cfg.projectId && cfg.gatewayKeyId) {\n\t    let response: Response;\n\t    try {\n\t      response = await fetch(`${cfg.baseURL}/api/v1/projects/${encodeURIComponent(cfg.projectId)}/keys/${encodeURIComponent(cfg.gatewayKeyId)}/revoke`, {\n\t        method: \"POST\",\n\t        headers: { authorization: `Bearer ${cfg.token}`, \"content-type\": \"application/json\", \"x-cave-csrf\": \"cli\" },\n\t        body: \"{}\",\n\t        signal: AbortSignal.timeout(5000),\n\t      });\n\t    } catch {\n\t      throw new Error(\"caveman: remote gateway key revocation was unavailable; credentials kept — retry `caveman logout`\");\n\t    }\n\t    if (!response.ok) {\n\t      const body = await response.json().catch(() => null) as { error?: { code?: unknown } } | null;\n\t      const alreadyRevoked = response.status === 404 && body?.error?.code === \"cave_key_not_found\";\n\t      if (!alreadyRevoked) throw new Error(`caveman: remote gateway key revocation failed (HTTP ${response.status}); credentials kept — retry \\`caveman logout\\``);\n\t    }\n\t  }\n\t  const headers: Record<string, string> = {\n\t    authorization: `Bearer ${cfg.token}`,\n\t    \"x-cave-client\": \"cli\",\n\t  };\n\t  const request: RequestInit = {\n\t    method: \"POST\",\n\t    redirect: \"manual\",\n\t    headers,\n\t    signal: AbortSignal.timeout(5000),\n\t  };\n\t  if (cfg.refreshToken) {","sourceCodeStart":9792,"sourceCodeEnd":9828,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9792-L9828","documentation":"Thrown during `caveman logout` when the POST to revoke the remote gateway key fails at the network level (fetch throws, e.g. DNS failure, connection refused, or the 5s AbortSignal.timeout fires). Credentials are intentionally kept locally so the user can retry instead of losing the token with a half-completed logout.","triggerScenarios":"`caveman logout` with the remote gateway unreachable: network down, baseURL host wrong, server down, or revocation call exceeding the 5000ms AbortSignal timeout.","commonSituations":"Logging out offline or on a captive-portal Wi-Fi; gateway under maintenance; slow VPN making the 5s timeout fire; misconfigured CAVE_BASE_URL pointing at a dead host.","solutions":["Restore network connectivity to the gateway and re-run `caveman logout` as the message advises.","Check `cfg.baseURL` / CAVE_BASE_URL is the correct reachable host.","Retry later if the gateway is under maintenance; local credentials were preserved.","If the 5s timeout is too tight on a slow link, retry when latency is lower."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: confirm the gateway is reachable before logging out\nconst ok = await fetch(`${baseURL}/healthz`, { signal: AbortSignal.timeout(5000) }).then(r => r.ok).catch(() => false);\nif (!ok) console.warn(\"Gateway unreachable — logout will keep credentials and must be retried.\");","typeGuard":null,"tryCatchPattern":"try {\n  await logout();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"revocation was unavailable\")) {\n    await new Promise(r => setTimeout(r, 2000));\n    await logout(); // credentials were kept, retry is safe\n  } else throw e;\n}","preventionTips":["Don't log out while offline or behind flaky proxies/VPNs.","Confirm the gateway host is reachable before logout.","Remember credentials are preserved on this failure — retrying is always safe."],"tags":["network","logout","http","credentials"],"backgroundTag":"network-request-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}