{"record":{"id":"2d4e2bb902be95a7","repo":"jlcodes99/cockpit-tools","slug":"backup-accounts-missing","errorCode":"backup_accounts_missing","errorMessage":"backup_accounts_missing","messagePattern":"backup_accounts_missing","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/scheduledBackupService.ts","lineNumber":303,"sourceCode":"  return deleted;\n}\n\nexport async function openAutoBackupDir(): Promise<void> {\n  await invoke('open_auto_backup_dir');\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction resolveBackupPlatformPayload(jsonContent: string, platform: PlatformId): unknown {\n  const parsed = JSON.parse(jsonContent) as unknown;\n  if (!isRecord(parsed)) {\n    throw new Error('invalid_backup_json');\n  }\n  const accountBundle = isRecord(parsed.accounts) ? parsed.accounts : parsed;\n  if (!isRecord(accountBundle.platforms)) {\n    throw new Error('backup_accounts_missing');\n  }\n  const payload = accountBundle.platforms[platform];\n  if (!isRecord(payload)) {\n    throw new Error('backup_platform_missing');\n  }\n  return payload.exported_data ?? payload.data ?? payload.accounts ?? [];\n}\n\nexport function extractAutoBackupPlatformJson(jsonContent: string, platform: PlatformId): string {\n  const payload = resolveBackupPlatformPayload(jsonContent, platform);\n  return JSON.stringify(payload, null, 2);\n}\n\nexport function normalizeAutoBackupPlatforms(\n  platforms: AutoBackupPlatformEntry[] | undefined,\n): AutoBackupPlatformEntry[] {\n  const countByPlatform = new Map<PlatformId, number>();\n  for (const item of platforms ?? []) {","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/services/scheduledBackupService.ts#L285-L321","documentation":"The backup file parsed as an object, but after unwrapping parsed.accounts the bundle has no platforms record. resolveBackupPlatformPayload requires accountBundle.platforms to be an object keyed by platform id in order to locate the requested platform's payload; without it there is nothing to extract, so it throws backup_accounts_missing.","triggerScenarios":"Calling payload()/extractAutoBackupPlatformJson with a JSON object that lacks both a top-level platforms object and an accounts.platforms object — e.g. a settings-only export, a manually trimmed backup, or a backup written by an older schema without platforms grouping.","commonSituations":"Restoring from a hand-edited or partial backup file, importing an export produced by a different tool/version whose bundle shape differs, or passing the inner accounts object to the API instead of the whole file.","solutions":["Open the backup file and confirm it contains a platforms object (top-level or under accounts) keyed by platform id","Use a backup file produced by createManagedBackup/exportDataTransferJson rather than a hand-built JSON","Upgrade/downgrade to matching versions if the file came from another app version with a different schema","Pass the full backup file content, not just the accounts sub-object"],"exampleFix":"// before: passing only the accounts section\nawait payload(JSON.stringify(bundle.accounts), 'zed');\n// after: pass the whole bundle\nif (!bundle.accounts?.platforms) throw new Error('backup has no platforms section');\nawait payload(JSON.stringify(bundle), 'zed');","handlingStrategy":"validation","validationCode":"const bundle = isRecord(parsed.accounts) ? parsed.accounts : parsed;\nif (!isRecord(bundle.platforms)) throw new Error('Backup has no platforms section');","typeGuard":"function hasPlatforms(v: unknown): v is { platforms: Record<string, unknown> } {\n  const b = (v as any)?.accounts ?? v;\n  return typeof b?.platforms === 'object' && b.platforms !== null && !Array.isArray(b.platforms);\n}","tryCatchPattern":"try {\n  const data = await payload(backupText, platform);\n} catch (e) {\n  if (e.message === 'backup_accounts_missing') {\n    console.error('Backup file lacks platforms map — not a valid auto-backup file');\n  } else throw e;\n}","preventionTips":["Restore only from files created by createManagedBackup/exportDataTransferJson","Pass the full file content, never a sub-object","Diff schema when restoring across app versions"],"tags":["backup","restore","schema","validation"],"backgroundTag":"invalid-backup-json","analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}