{"record":{"id":"c101b48404751cca","repo":"diegosouzapw/OmniRoute","slug":"openrouterproviderstats-failed-to-write-cache","errorCode":null,"errorMessage":"[OpenRouterProviderStats] Failed to write cache:","messagePattern":"\\[OpenRouterProviderStats\\] Failed to write cache:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/lib/catalog/openrouterProviderStats.ts","lineNumber":241,"sourceCode":"}\n\nfunction readCache(): CacheFile | null {\n  const filePath = getCacheFilePath();\n  try {\n    if (!fs.existsSync(filePath)) return null;\n    return JSON.parse(fs.readFileSync(filePath, \"utf8\")) as CacheFile;\n  } catch {\n    return null;\n  }\n}\n\nfunction writeCache(data: ProviderPopularityEntry[]): void {\n  const filePath = getCacheFilePath();\n  const cache: CacheFile = { fetchedAt: new Date().toISOString(), data };\n  try {\n    fs.writeFileSync(filePath, JSON.stringify(cache, null, 2), \"utf8\");\n  } catch (err) {\n    console.warn(\"[OpenRouterProviderStats] Failed to write cache:\", err);\n  }\n}\n\n/** Get provider popularity/enrichment stats, honoring the on-disk TTL cache. */\nexport async function getOpenRouterProviderStats(): Promise<{\n  data: ProviderPopularityEntry[];\n  stale: boolean;\n  cachedAt: string | null;\n  fromCache: boolean;\n}> {\n  const ttl = getTTL();\n  const cache = readCache();\n  const now = Date.now();\n\n  if (cache && cache.fetchedAt) {\n    const age = now - new Date(cache.fetchedAt).getTime();\n    if (age < ttl) {\n      return { data: cache.data, stale: false, cachedAt: cache.fetchedAt, fromCache: true };","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/lib/catalog/openrouterProviderStats.ts#L223-L259","documentation":"Error \"[OpenRouterProviderStats] Failed to write cache:\" thrown in diegosouzapw/OmniRoute.","triggerScenarios":"Thrown at src/lib/catalog/openrouterProviderStats.ts:241 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","schemaVersion":2},"datasetVersion":"2026-08-25T21:54:21.419Z"}