jlcodes99/cockpit-tools · error

backup_platform_missing

backup_platform_missing

Error message

backup_platform_missing

What it means

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.

Source

Thrown at src/services/scheduledBackupService.ts:307

  await invoke('open_auto_backup_dir');
}

function isRecord(value: unknown): value is Record<string, unknown> {
  return typeof value === 'object' && value !== null && !Array.isArray(value);
}

function resolveBackupPlatformPayload(jsonContent: string, platform: PlatformId): unknown {
  const parsed = JSON.parse(jsonContent) as unknown;
  if (!isRecord(parsed)) {
    throw new Error('invalid_backup_json');
  }
  const accountBundle = isRecord(parsed.accounts) ? parsed.accounts : parsed;
  if (!isRecord(accountBundle.platforms)) {
    throw new Error('backup_accounts_missing');
  }
  const payload = accountBundle.platforms[platform];
  if (!isRecord(payload)) {
    throw new Error('backup_platform_missing');
  }
  return payload.exported_data ?? payload.data ?? payload.accounts ?? [];
}

export function extractAutoBackupPlatformJson(jsonContent: string, platform: PlatformId): string {
  const payload = resolveBackupPlatformPayload(jsonContent, platform);
  return JSON.stringify(payload, null, 2);
}

export function normalizeAutoBackupPlatforms(
  platforms: AutoBackupPlatformEntry[] | undefined,
): AutoBackupPlatformEntry[] {
  const countByPlatform = new Map<PlatformId, number>();
  for (const item of platforms ?? []) {
    if (!ALL_PLATFORM_IDS.includes(item.platform)) continue;
    const count = Number.isFinite(item.account_count)
      ? Math.max(0, Math.floor(item.account_count))
      : 0;

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Inspect backup.platforms to see which platform keys the file actually contains
  2. Request a platform id that exists in the file, or select the correct backup file for that platform
  3. Create a fresh backup that includes the platform's accounts, then restore from it
  4. Verify the platform id string matches exactly the PlatformId used in the app

Example fix

// before
const zed = await payload(backupText, 'zed'); // throws if zed not in backup
// after
const bundle = JSON.parse(backupText).accounts ?? JSON.parse(backupText);
if (!bundle.platforms?.zed) {
  console.warn('No zed payload in this backup; available:', Object.keys(bundle.platforms ?? {}));
  return;
}
const zed = await payload(backupText, 'zed');
Defensive patterns

Strategy: validation

Validate before calling

const bundle = isRecord(parsed.accounts) ? parsed.accounts : parsed;
if (!(platform in (bundle.platforms ?? {}))) {
  console.warn(`Backup contains platforms: ${Object.keys(bundle.platforms ?? {}).join(', ')}`);
}

Type guard

function backupHasPlatform(v: unknown, platform: string): boolean {
  const b = (v as any)?.accounts ?? v;
  const p = b?.platforms;
  return typeof p === 'object' && p !== null && typeof p[platform] === 'object' && p[platform] !== null;
}

Try / catch

try {
  const data = await payload(backupText, platform);
} catch (e) {
  if (e.message === 'backup_platform_missing') {
    notify(`This backup has no data for ${platform}; pick another backup or skip`);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jlcodes99/cockpit-tools@1ed8b77992 (2026-09-05). Data as JSON: /api/errors/99195bea940547a4. Report an issue: GitHub.