{"record":{"id":"3bc4152e4c451063","repo":"santifer/career-ops","slug":"validation-failed-err-message-and-revert-also","errorCode":null,"errorMessage":"Validation failed (${err.message}) and revert also failed (${revertErr.message})","messagePattern":"Validation failed \\((.+?)\\) and revert also failed \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"update-system.mjs","lineNumber":2427,"sourceCode":"      const changed = gitStatusEntries()\n        .map((entry) => entry.path)\n        .filter((file) => !initialStatusPaths.has(file) && !generatedBackupPaths.has(file));\n      for (const file of userLayerViolations(changed, updatePaths, effectiveUserPaths())) {\n        console.error(`SAFETY VIOLATION: User file was modified: ${file}`);\n        violatedUserPaths.add(file);\n      }\n    } catch (err) {\n      // Fail closed: if we can't validate the safety invariant we must\n      // not silently proceed — that would let a real violation slip\n      // through. Revert what we already applied and abort.\n      console.error(`Aborting: could not validate user-layer safety (${err.message}).`);\n      try {\n        revertPaths(updated, initialStatusPaths);\n      } catch (revertErr) {\n        // If the revert itself fails (likely whatever broke `git\n        // status` also broke `git checkout --`), don't lose the\n        // original validation error — chain it via `cause`.\n        throw new Error(\n          `Validation failed (${err.message}) and revert also failed (${revertErr.message})`,\n          { cause: err },\n        );\n      }\n      throw err;\n    }\n\n    if (violatedUserPaths.size > 0) {\n      console.error('Aborting: user files were touched. Rolling back system files...');\n      // Revert ONLY the system-layer updates — never `git checkout` the\n      // violated user paths back to HEAD. Doing so would overwrite the\n      // user's working-tree content (accumulated STAR+R stories, local\n      // edits) with whatever is committed upstream, causing data loss.\n      // The user files were flagged as touched by the update, not by the\n      // user; leaving them as-is is the safe choice — the user decides\n      // what to do with them.\n      const violation = new Error('Update aborted: user files were touched.');\n      try {","sourceCodeStart":2409,"sourceCodeEnd":2445,"githubUrl":"https://github.com/santifer/career-ops/blob/e7abd431fce9348a95261acac9e0c14779c35df8/update-system.mjs#L2409-L2445","documentation":"After applying updates, update-system.mjs validates the result (e.g. via git status). If validation fails it tries to revert the touched paths with revertPaths(); if that revert also fails, it throws this combined error chaining the original validation failure via `cause` so neither diagnostic is lost. It signals the worktree is in an unknown, partially-reverted state needing manual attention.","triggerScenarios":"Post-apply validation threw (err), revertPaths(updated, initialStatusPaths) also threw (revertErr) — typically because whatever broke `git status` (index lock, corrupt index) also breaks `git checkout --`.","commonSituations":"A stale .git/index.lock left by another git process; concurrent git operations during the update; disk-full or permission problems in the repo; an editor or watcher holding files during apply.","solutions":["Read err.cause (`cause`) to see the original validation error and fix that root problem.","Remove a stale lock file if present: check for .git/index.lock and delete it if no git process is running.","Manually revert the updated files: `git checkout -- <paths>` or `git restore <paths>`.","Re-run `node update-system.mjs apply --confirm` after the repo is healthy."],"exampleFix":"# before (broken state)\nrm -f .git/index.lock\ngit restore modes/ scripts/  # or: git checkout -- .\n# after\nnode update-system.mjs apply --confirm","handlingStrategy":"try-catch","validationCode":"// before applying, ensure the repo is healthy:\nexecFileSync('git', ['status', '--porcelain'], { cwd: ROOT });\nexecFileSync('git', ['diff', '--quiet']);","typeGuard":null,"tryCatchPattern":"try {\n  applyUpdate();\n} catch (e) {\n  if (e.message.startsWith('Validation failed') && e.cause) {\n    console.error('root cause:', e.cause.message);\n    console.error('revert manually: git restore .');\n  } else throw e;\n}","preventionTips":["Clear stale .git/index.lock before running updates.","Run the updater when no other git process is active.","Keep sufficient disk space and writable repo permissions.","Commit or stash local changes before applying updates."],"tags":["git","revert-failed","state-corruption"],"backgroundTag":"git-command-failed","analyzedSha":"e7abd431fce9348a95261acac9e0c14779c35df8","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}