{"record":{"id":"99195bea940547a4","repo":"jlcodes99/cockpit-tools","slug":"backup-platform-missing","errorCode":"backup_platform_missing","errorMessage":"backup_platform_missing","messagePattern":"backup_platform_missing","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/scheduledBackupService.ts","lineNumber":307,"sourceCode":"  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 ?? []) {\n    if (!ALL_PLATFORM_IDS.includes(item.platform)) continue;\n    const count = Number.isFinite(item.account_count)\n      ? Math.max(0, Math.floor(item.account_count))\n      : 0;","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/services/scheduledBackupService.ts#L289-L325","documentation":"The backup file has a platforms record, but there is no entry under the requested platform id (accountBundle.platforms[platform] is missing or not an object). The library cannot fabricate data for a platform that was never backed up, so it throws backup_platform_missing.","triggerScenarios":"Calling payload()/extractAutoBackupPlatformJson with a platform id that is absent from the backup's platforms map — restoring a Qoder backup and asking for the Zed payload, or a backup taken before that platform's accounts existed.","commonSituations":"Restoring a partial/filtered backup on a new machine, platform id typo or case mismatch, or an auto-backup created when the platform had no accounts so its key was omitted.","solutions":["Inspect backup.platforms to see which platform keys the file actually contains","Request a platform id that exists in the file, or select the correct backup file for that platform","Create a fresh backup that includes the platform's accounts, then restore from it","Verify the platform id string matches exactly the PlatformId used in the app"],"exampleFix":"// before\nconst zed = await payload(backupText, 'zed'); // throws if zed not in backup\n// after\nconst bundle = JSON.parse(backupText).accounts ?? JSON.parse(backupText);\nif (!bundle.platforms?.zed) {\n  console.warn('No zed payload in this backup; available:', Object.keys(bundle.platforms ?? {}));\n  return;\n}\nconst zed = await payload(backupText, 'zed');","handlingStrategy":"validation","validationCode":"const bundle = isRecord(parsed.accounts) ? parsed.accounts : parsed;\nif (!(platform in (bundle.platforms ?? {}))) {\n  console.warn(`Backup contains platforms: ${Object.keys(bundle.platforms ?? {}).join(', ')}`);\n}","typeGuard":"function backupHasPlatform(v: unknown, platform: string): boolean {\n  const b = (v as any)?.accounts ?? v;\n  const p = b?.platforms;\n  return typeof p === 'object' && p !== null && typeof p[platform] === 'object' && p[platform] !== null;\n}","tryCatchPattern":"try {\n  const data = await payload(backupText, platform);\n} catch (e) {\n  if (e.message === 'backup_platform_missing') {\n    notify(`This backup has no data for ${platform}; pick another backup or skip`);\n  } else throw e;\n}","preventionTips":["List available platform keys from the backup before restore","Match the backup file to the platform being restored","Re-backup after enabling a new platform","Watch for id typos/case mismatches"],"tags":["backup","restore","platform","missing-key"],"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"}