{"record":{"id":"2b4baec0828fc9a0","repo":"paperclipai/paperclip","slug":"refusing-to-overwrite-invalid-config-at-filepath","errorCode":null,"errorMessage":"Refusing to overwrite invalid config at ${filePath}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Refusing to overwrite invalid config at (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/config/store.ts","lineNumber":206,"sourceCode":"  configPath?: string,\n  options: { invalidBackupPath?: string } = {},\n): boolean {\n  const filePath = resolveConfigPath(configPath);\n  const dir = path.dirname(filePath);\n  fs.mkdirSync(dir, { recursive: true });\n\n  let nextConfig = paperclipConfigSchema.parse(config);\n  if (fs.existsSync(filePath)) {\n    try {\n      const source = paperclipConfigSchema.parse(migrateLegacyConfig(parseJson(filePath)));\n      nextConfig = paperclipConfigSchema.parse(mergePaperclipConfig(source, nextConfig));\n      if (isDeepStrictEqual(effectiveConfig(source), effectiveConfig(nextConfig))) {\n        return false;\n      }\n    } catch (error) {\n      const invalidBackupPath = options.invalidBackupPath;\n      if (!invalidBackupPath) {\n        throw new Error(\n          `Refusing to overwrite invalid config at ${filePath}: ${error instanceof Error ? error.message : String(error)}`,\n        );\n      }\n      if (\n        !fs.existsSync(invalidBackupPath) ||\n        !fs.readFileSync(filePath).equals(fs.readFileSync(invalidBackupPath))\n      ) {\n        throw new Error(\n          `Refusing to overwrite ${filePath} because it changed after the invalid backup was created`,\n        );\n      }\n    }\n  }\n\n  // Backup existing config before overwriting\n  if (fs.existsSync(filePath)) {\n    const backupPath = filePath + \".backup\";\n    durableCopyFile(filePath, backupPath);","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/cli/src/config/store.ts#L188-L224","documentation":"writeConfig tried to merge over the existing config file and it failed schema or JSON validation; without a backup path it refuses to clobber a file it cannot understand.","triggerScenarios":"Thrown at cli/src/config/store.ts:206 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix or remove the invalid config at ${filePath} so it can be backed up and rewritten safely.","Restore a valid config from the existing backup, then retry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}