{"record":{"id":"4bcf6472cf54dfd1","repo":"Foundry376/Mailspring","slug":"unrecognized-mbox-export-manifest-in-stagingdir","errorCode":null,"errorMessage":"Unrecognized mbox export manifest in ${stagingDir}","messagePattern":"Unrecognized mbox export manifest in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/services/mbox-utils.ts","lineNumber":146,"sourceCode":"export function readMboxExportManifest(stagingDir: string): MboxExportManifest | null {\n  let raw: string;\n  try {\n    raw = fs.readFileSync(path.join(stagingDir, MANIFEST_NAME), 'utf8');\n  } catch (err) {\n    // no manifest — no assembly has happened yet\n    return null;\n  }\n  // An unreadable manifest must NOT be treated as a fresh export: that would\n  // truncate the mbox to zero even though consumed messages exist only there.\n  // Failing loudly preserves both the mbox and the remaining staged files.\n  let parsed = null;\n  try {\n    parsed = JSON.parse(raw);\n  } catch (err) {\n    // fall through to the error below\n  }\n  if (!parsed || parsed.version !== 1 || typeof parsed.mboxBytes !== 'number') {\n    throw new Error(`Unrecognized mbox export manifest in ${stagingDir}`);\n  }\n  return parsed as MboxExportManifest;\n}\n\nasync function writeManifest(stagingDir: string, manifest: MboxExportManifest) {\n  const dest = path.join(stagingDir, MANIFEST_NAME);\n  const tmp = `${dest}.tmp`;\n  const fh = await fs.promises.open(tmp, 'w');\n  try {\n    await fh.writeFile(JSON.stringify(manifest), 'utf8');\n    await fh.sync();\n  } finally {\n    await fh.close();\n  }\n  await fs.promises.rename(tmp, dest);\n  // Make the rename durable before the caller deletes consumed files: on\n  // power loss the deletes must never outlive the manifest that records\n  // them. Directories can't be fsynced on Windows — best effort there.","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/Foundry376/Mailspring/blob/648c685d602ece6bb00c22534b8734de6ac644b3/app/src/services/mbox-utils.ts#L128-L164","documentation":"readMboxExportManifest throws when the manifest file exists in the staging directory but its contents are not valid JSON. It must fail loudly rather than return null, because treating a corrupt manifest as 'no export yet' would truncate the mbox even though consumed messages exist only there.","triggerScenarios":"Thrown at app/src/services/mbox-utils.ts:146 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the manifest JSON in the staging directory and repair or restore it from backup","If the export is genuinely broken, delete both the staging dir and mbox and re-run the export","Do not delete the mbox — it may be the only copy of already-consumed messages"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"648c685d602ece6bb00c22534b8734de6ac644b3","analyzedAt":"2026-09-03T02:00:24.311Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}