{"record":{"id":"ee074b1b78ab72ad","repo":"gatsbyjs/gatsby","slug":"json-file-store-failed-to-json-parse-this-string","errorCode":null,"errorMessage":"json-file-store failed to JSON.parse this string: `${dataString.replace(/\\n/g, `⏎`)}`","messagePattern":"json-file-store failed to JSON\\.parse this string: `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby/src/cache/json-file-store.ts","lineNumber":141,"sourceCode":"        // JSON.parse is sync so we need to return a buffer sync, we will fill the buffer later\n        const buffer = Buffer.alloc(value.size)\n        externalBuffers.push({\n          index: +value.index,\n          buffer: buffer,\n        })\n        return buffer\n      } else if (\n        value &&\n        value.type === `Infinity` &&\n        typeof value.sign === `number`\n      ) {\n        return Infinity * value.sign\n      } else {\n        return value\n      }\n    })\n  } catch (e) {\n    throw new Error(\n      \"json-file-store failed to JSON.parse this string: `\" +\n        dataString.replace(/\\n/g, `⏎`)\n    )\n  }\n\n  // read external buffers\n  await Promise.all(\n    externalBuffers.map(async function (externalBuffer) {\n      if (options.zip) {\n        const bufferCompressed = await promisify(fs.readFile)(\n          path + `-` + +externalBuffer.index + `.bin` + zipExtension\n        )\n        const buffer = await promisify(zlib.unzip)(bufferCompressed)\n        buffer.copy(externalBuffer.buffer)\n      } else {\n        const fd = await promisify(fs.open)(\n          path + `-` + +externalBuffer.index + `.bin` + zipExtension,\n          `r`","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby/src/cache/json-file-store.ts#L123-L159","documentation":"`json-file-store` persists Gatsby's cache as JSON and parses it back with a reviver. When `JSON.parse` throws, the raw string is shown with newlines visualised as `⏎` so corruption is diagnosable. Typical cause is a truncated/garbled cache file.","triggerScenarios":"The cache file on disk contains bytes that are not valid JSON (truncated write, concurrent writers, disk-full, manual edit).","commonSituations":"Build killed mid-write (`SIGKILL`, OOM, power loss); out of disk; switching Node/Gatsby versions over the same `.cache`; editor saving over a cache file.","solutions":["Delete `.cache` (and `public` for a clean build) and re-run.","Check disk space and that no other process is writing to `.cache`.","Ensure builds shut down gracefully so writes can complete.","If reproducible on a clean cache, capture the failing file and file a Gatsby issue."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: ensure cache files parse; if not, clear before build.\nconst fs = require(\"fs\")\nfunction ensureCacheValid(file) {\n  try { JSON.parse(fs.readFileSync(file, \"utf8\")) } catch { fs.rmSync(\".cache\", { recursive: true, force: true }) }\n}\n","typeGuard":null,"tryCatchPattern":"// CI build wrapper: one cache-clear retry on parse failure.\ntry { await build() }\ncatch (e) {\n  if (/json-file-store failed to JSON.parse/.test(String(e))) {\n  fs.rmSync(\".cache\", { recursive: true, force: true })\n  await build()\n  } else throw e\n}\n","preventionTips":["Always clear `.cache` when switching branches/Node/Gatsby versions.","Ensure graceful shutdown of dev/build to avoid truncated cache writes.","Monitor disk space on CI runners."],"tags":["cache","json","filesystem","internal"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}