{"record":{"id":"c17bf481c0c01fa1","repo":"koala73/worldmonitor","slug":"resilience-indicator-response-cache-returned-no-da","errorCode":null,"errorMessage":"Resilience indicator response cache returned no data","messagePattern":"Resilience indicator response cache returned no data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/worldmonitor/resilience/v1/get-resilience-indicators.ts","lineNumber":336,"sourceCode":"        scores,\n        materializeIndicatorTrace(trace, scores),\n        { now: now(), dataVersion },\n      );\n    };\n\n    if (!responseCache) return buildResponse();\n    const constructs = getConstructVersions();\n    const cacheKey = [\n      'resilience:indicator-trace:v1',\n      countryCode,\n      getCurrentCacheFormula(),\n      RESILIENCE_SCHEMA_V2_ENABLED ? 'schema-v2' : 'schema-v1',\n      `energy-${constructs.energy}`,\n      `education-${constructs.education}`,\n      `financial-system-${constructs.financialSystemExposure}`,\n    ].join(':');\n    const cached = await responseCache(cacheKey, buildResponse);\n    if (cached == null) throw new Error('Resilience indicator response cache returned no data');\n    return cached;\n  };\n}\n\nexport const getResilienceIndicators = createGetResilienceIndicators();\n","sourceCodeStart":318,"sourceCodeEnd":342,"githubUrl":"https://github.com/koala73/worldmonitor/blob/9361220cc013571781071f0206e4d80fd14b2f7f/server/worldmonitor/resilience/v1/get-resilience-indicators.ts#L318-L342","documentation":"Thrown in createGetResilienceIndicators (get-resilience-indicators.ts) when the layered responseCache() wrapper resolves to null/undefined even though a buildResponse fallback was supplied. The code builds a composite cache key (schema version + construct selections) and expects the cache helper to either return a cached response or the freshly built one; a null result means the cache layer could neither read nor safely store the response, so the handler refuses to return an empty/undefined payload.","triggerScenarios":"Calling getResilienceIndicators when responseCache(cacheKey, buildResponse) returns null — e.g., the cache backend errors on both GET and SET, buildResponse itself returns null, or the cache helper is misconfigured/absent (dependencies.responseCache undefined paths handled above this line) yet a null still slips through.","commonSituations":"1) Redis/Upstash outage combined with a buildResponse that fails and returns null; 2) cache helper returning null on serialization failures of a large schema-v2 payload; 3) wiring mistake in dependencies that passes a broken responseCache stub in tests or preview environments.","solutions":["Check cache backend health and credentials; the cache layer failing both read and write is the usual root cause.","Verify dependencies.responseCache is wired to the real cachedFetchJson-based helper in this deployment, not a stub that returns null.","Inspect buildResponse: it must always resolve to a valid GetResilienceIndicatorsResponse; fix any path where it returns null.","Retry after the transient cache outage, or add a direct fallback that calls buildResponse() when the cache layer returns null."],"exampleFix":"// before\nconst cached = await responseCache(cacheKey, buildResponse);\nif (cached == null) throw new Error('Resilience indicator response cache returned no data');\n// after\nlet cached = await responseCache(cacheKey, buildResponse);\nif (cached == null) {\n  console.warn(`response cache returned no data for ${cacheKey}; building directly`);\n  cached = await buildResponse();\n}\nif (cached == null) throw new Error('Resilience indicator response cache returned no data');","handlingStrategy":"fallback","validationCode":"// before the call, confirm cache dependency is wired\nif (!dependencies.responseCache) console.warn('responseCache missing; null results likely');","typeGuard":"function isIndicatorsResponse(v: unknown): v is GetResilienceIndicatorsResponse {\n  return typeof v === 'object' && v !== null && 'countryCode' in v && Array.isArray((v as any).indicators);\n}","tryCatchPattern":"try {\n  return await getResilienceIndicators(req);\n} catch (err) {\n  if (err.message === 'Resilience indicator response cache returned no data') {\n    return buildIndicatorsDirectly(req); // bypass cache layer\n  }\n  throw err;\n}","preventionTips":["Health-check the cache backend and alert on GET/SET failures","Ensure buildResponse never resolves null","Use the real cachedFetchJson-based helper in all environments","Retry once on this error before surfacing it to clients"],"tags":["cache","null-response","server","fallback"],"backgroundTag":"cache-miss-null-response","analyzedSha":"9361220cc013571781071f0206e4d80fd14b2f7f","analyzedAt":"2026-09-01T10:32:37.851Z","contentChangedAt":"2026-09-01T10:32:37.851Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}