{"record":{"id":"5cd0d2551baf50e6","repo":"chatboxai/chatbox","slug":"resource-was-not-staged-resource-path","errorCode":null,"errorMessage":"Resource was not staged: ${resource.path}","messagePattern":"Resource was not staged: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/renderer/packages/backup/import-backup.ts","lineNumber":137,"sourceCode":"      }\n    }\n    const candidate = `${candidatePrefix}:${uuidv4()}`\n    if (!reserved.has(candidate) && (await storage.getBlob(candidate)) === null) return candidate\n  }\n  throw new Error(`Could not allocate a resource key for: ${originalKey}`)\n}\n\nasync function createResourcePlans(\n  manifest: BackupManifest,\n  stagedEntries: Map<string, StagedEntry>,\n  storage: BackupStorage\n) {\n  const plans: ResourceWritePlan[] = []\n  const resourceKeyMap = new Map<string, string>()\n  const reserved = new Set<string>()\n  for (const resource of manifest.resources) {\n    const staged = stagedEntries.get(resource.path)\n    if (!staged?.tempKey) throw new Error(`Resource was not staged: ${resource.path}`)\n    const restoredValue = await readStagedResource(storage, { resource, tempKey: staged.tempKey })\n    const targets: ResourceWritePlan['targets'] = []\n    for (const originalKey of resource.originalStorageKeys) {\n      const existingValue = await storage.getBlob(originalKey)\n      let targetKey = originalKey\n      let needsWrite = existingValue === null\n      if (existingValue !== null && existingValue !== restoredValue) {\n        targetKey = await findAvailableCollisionKey(storage, originalKey, reserved)\n        needsWrite = true\n      }\n      if (reserved.has(targetKey)) {\n        targetKey = await findAvailableCollisionKey(storage, originalKey, reserved)\n        needsWrite = true\n      }\n      reserved.add(targetKey)\n      resourceKeyMap.set(originalKey, targetKey)\n      targets.push({ originalKey, targetKey, needsWrite })\n    }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/renderer/packages/backup/import-backup.ts#L119-L155","documentation":"Thrown by createResourcePlans when a manifest resource's path has no staged entry or its staged entry lacks a tempKey. Reading normally stages every resource under a temp blob key (lines 244-248); reaching this throw means staging and the manifest disagree. Propagates after rollback.","triggerScenarios":"manifest.resources[i].path is absent from stagedEntries, or its staged entry has tempKey undefined when createResourcePlans runs.","commonSituations":"Normally caught earlier by validateManifestEntries (error 126). Reachable if validation was skipped, if a resource path was staged via the JSON branch instead of the resource branch due to an isBackupResourcePath mismatch, or if tempKey assignment changed.","solutions":["Ensure validateManifestEntries runs before createResourcePlans (it does in importBackupArchive).","Confirm isBackupResourcePath classifies every manifest resource path as a resource during the reading phase.","If the manifest was edited, restore it so it matches the archive.","Regenerate the backup."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before import, ensure every resource path was staged with a tempKey during reading.\nfor (const r of manifest.resources) {\n  const staged = stagedEntries.get(r.path)\n  if (!staged?.tempKey) throw new Error('Resource not staged: ' + r.path)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await importBackupArchive(file, options)\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('Resource was not staged')) {\n    // Usually means validateManifestEntries was bypassed; re-run it before createResourcePlans.\n    throw new Error('Resource staging incomplete', { cause: error })\n  }\n  throw error\n}","preventionTips":["Always run validateManifestEntries before createResourcePlans.","Keep isBackupResourcePath classification consistent between the reading switch and manifest resource paths.","Regenerate backups rather than hand-editing resource entries."],"tags":["backup","import","resource","staging","defensive"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}