{"record":{"id":"941212ca0dc27bb1","repo":"different-ai/openwork","slug":"den-returned-an-invalid-diagnostics-configuration","errorCode":null,"errorMessage":"Den returned an invalid diagnostics configuration response.","messagePattern":"Den returned an invalid diagnostics configuration response\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/egress-diagnostics-card.tsx","lineNumber":108,"sourceCode":"  const [bearerTokenDraft, setBearerTokenDraft] = useState(\"\");\n  const [savingBearerToken, setSavingBearerToken] = useState(false);\n  const [editingBearerToken, setEditingBearerToken] = useState(false);\n\n  useEffect(() => {\n    if (!canView) {\n      setLoading(false);\n      return;\n    }\n    let cancelled = false;\n    async function loadConfiguration() {\n      setLoading(true);\n      try {\n        const { response, payload } = await requestJson(\"/v1/diagnostics/egress\", { method: \"GET\" }, 12_000);\n        if (!response.ok) {\n          throw new Error(getErrorMessage(payload, `Could not load egress diagnostics (${response.status}).`));\n        }\n        const parsed = egressDiagnosticConfigurationSchema.safeParse(payload);\n        if (!parsed.success) throw new Error(\"Den returned an invalid diagnostics configuration response.\");\n        if (!cancelled) {\n          setAvailable(parsed.data.available);\n          setTargetOrigin(parsed.data.targetOrigin);\n          setMissingConfiguration(parsed.data.missingConfiguration);\n          setError(null);\n        }\n      } catch (loadError) {\n        if (!cancelled) setError(loadError instanceof Error ? loadError.message : \"Could not load egress diagnostics.\");\n      } finally {\n        if (!cancelled) setLoading(false);\n      }\n    }\n    void loadConfiguration();\n    return () => { cancelled = true; };\n  }, [canView]);\n\n  useEffect(() => {\n    if (!copied) return;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/egress-diagnostics-card.tsx#L90-L126","documentation":"After a successful (2xx) GET /v1/diagnostics/egress, loadConfiguration validates the payload against egressDiagnosticConfigurationSchema with safeParse. If the payload doesn't match the expected shape (available, targetOrigin, missingConfiguration, etc.), it throws \"Den returned an invalid diagnostics configuration response.\" This is a client-side contract check protecting the UI from malformed or unexpected server data.","triggerScenarios":"The server returns 200 but the JSON body is not a valid diagnostics configuration: an HTML error page served as 200 by a proxy, an empty body, a different schema from an older/newer Den server, or a gateway (e.g. login portal) intercepting the route.","commonSituations":"Version skew between dashboard and Den server (schema drift); misconfigured reverse proxy answering 200 with HTML; authenticated Wi-Fi/captive portal injecting a page; a CDN cache serving a stale or wrong payload.","solutions":["Log/inspect the raw payload from GET /v1/diagnostics/egress and compare it against egressDiagnosticConfigurationSchema to find the mismatched field.","Align versions: update the dashboard or Den server so both sides use the same diagnostics configuration schema.","Check for a reverse proxy or captive portal returning 200 with non-JSON content and fix the proxy routing for /v1/*.","Clear any CDN/proxy cache in front of the Den API and retry."],"exampleFix":"// before (older Den server omits missingConfiguration)\n// payload: { available: true, targetOrigin: \"https://x\" } -> safeParse fails\n\n// after: upgrade Den so the 200 payload matches the schema\n// payload: { available: true, targetOrigin: \"https://x\", missingConfiguration: [] }","handlingStrategy":"type-guard","validationCode":"const payloadIsJsonObject =\n  typeof payload === \"object\" && payload !== null && \"available\" in payload && \"targetOrigin\" in payload;\nif (!payloadIsJsonObject) throw new Error(\"Unexpected diagnostics payload shape before schema parse.\");","typeGuard":"function looksLikeEgressConfig(p: unknown): p is { available: boolean; targetOrigin: string; missingConfiguration?: unknown } {\n  return typeof p === \"object\" && p !== null\n    && \"available\" in p && typeof (p as { available: unknown }).available === \"boolean\"\n    && \"targetOrigin\" in p && typeof (p as { targetOrigin: unknown }).targetOrigin === \"string\";\n}","tryCatchPattern":"try {\n  await loadConfiguration();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"invalid diagnostics configuration\")) {\n    console.error(\"Contract mismatch on /v1/diagnostics/egress — check server version/proxy.\", e);\n    showError(\"Diagnostics data from Den is unreadable; verify server version.\");\n  } else throw e;\n}","preventionTips":["Log the raw payload on schema failure to speed up contract debugging.","Pin dashboard and Den server to matching versions to avoid schema drift.","Ensure proxies/captive portals never answer /v1/* routes with 200 + HTML.","Add a server-side smoke test asserting the 200 body parses against the schema."],"tags":["schema","zod","validation","api-contract"],"backgroundTag":"schema-validation-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}