{"record":{"id":"652b58e5d6edda17","repo":"overleaf/overleaf","slug":"fatal-error","errorCode":null,"errorMessage":"fatal error","messagePattern":"fatal error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/project-history/scripts/bulk_resync_file_fix_up.mjs","lineNumber":325,"sourceCode":"try {\n  try {\n    await main()\n  } finally {\n    clearInterval(logInterval)\n    logStats()\n    Metrics.close()\n    await mongoClient.close()\n    // TODO(das7pad): graceful shutdown for redis. Refactor process.exit when done.\n  }\n  console.log('Done.')\n  await setTimeout(1_000)\n  if (STATS.failure) {\n    process.exit(Math.min(STATS.failure, 99))\n  } else {\n    process.exit(0)\n  }\n} catch (err) {\n  logger.err({ err }, 'fatal error')\n  await setTimeout(1_000)\n  process.exit(100)\n}\n","sourceCodeStart":307,"sourceCodeEnd":329,"githubUrl":"https://github.com/overleaf/overleaf/blob/28ad3b03b71cb4311decdcb55c36b33ec10d72db/services/project-history/scripts/bulk_resync_file_fix_up.mjs#L307-L329","documentation":"This is the top-level catch-all of the bulk_resync_file_fix_up script. Any uncaught error from the main flow (e.g. a rethrown flush failure, DB connection loss, iteration crash) is logged as 'fatal error' and the process exits with code 100. It is a wrapper, not a domain error; the real cause is in the logged err object.","triggerScenarios":"Any throw escaping the main try block: rethrown flush errors during shutdown, mongo/redis connection failures, or bugs in the batch loop.","commonSituations":"Database credential/config changes mid-run, network partition to mongo/redis, unhandled exceptions in the resync loop, manual kill causing state races.","solutions":["Read the err field in the 'fatal error' log line to identify the root cause; exit code 100 only signals an unhandled crash.","Re-run the script once mongo/redis connectivity and credentials are verified (the script is resumable/idempotent for remaining projects).","Check STATS.failure counts in earlier logs to see how many projects failed before the crash.","If crashes recur at the same project, inspect that project's data for corruption or malformed records."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await main()\n} catch (err) {\n  logger.err({ err, stack: err.stack, cause: err.cause }, 'fatal error')\n  process.exitCode = 100\n}","preventionTips":["Always read the err object in the 'fatal error' log before acting; exit code 100 is only a wrapper signal.","Pre-validate mongo/redis connectivity before starting the batch.","Wrap per-project work in its own try/catch so one bad project can't kill the whole run.","Record progress/checkpoints so re-runs after a crash are cheap."],"tags":["fatal","exit-code","batch-script","project-history"],"backgroundTag":"unhandled-exception-crash","analyzedSha":"28ad3b03b71cb4311decdcb55c36b33ec10d72db","analyzedAt":"2026-09-03T02:10:22.807Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}