jlcodes99/cockpit-tools · error

messages.noItems

Error message

messages.noItems

What it means

The parsed bundle unwrapped (through 'data' and any nested string payload) to a top-level JSON array that is empty. An empty items list cannot create any accounts, so messages.noItems is thrown (line 411).

Solutions

  1. Export again after confirming the source has at least one account
  2. Remove filters/limits on the export that excluded all items
  3. If you meant to import a single account, use its object (not an empty array) as the bundle

Example fix

// before
{"data":[]}
// after
{"data":[{"refresh_token":"rt_a"}]}
Defensive patterns

Strategy: validation

Validate before calling

const bundle: unknown = JSON.parse(content);
const root = bundle && typeof bundle === 'object' && 'data' in bundle ? (bundle as {data?: unknown}).data : bundle;
if (Array.isArray(root) && root.length === 0) throw new Error('Export contains no items');

Type guard

const isNonEmptyArray = (v: unknown): v is unknown[] =>
  Array.isArray(v) && v.length > 0;

Try / catch

try {
  items = resolveExternalImportBundleItems(content, platformId, messages);
} catch (e) {
  if (e instanceof Error && e.message === messages.noItems) {
    notifyEmptyExport();
  }
}

Prevention

When it happens

Trigger: JSON parses fine, root (after envelope unwrap) is an array with length 0.

Common situations: Source account list is genuinely empty (nothing exported yet); export filter excluded all accounts; API returned success with an empty data array; deleted-all-accounts export.

Related errors


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

Appendix: source

Thrown at src/hooks/useProviderAccountsPage.ts:411

          readBundleMessage((parsed as { message?: unknown }).message) ??
          readBundleMessage((parsed as { error?: unknown }).error) ??
          messages.empty,
      );
    }
  }

  const root =
    parsed && typeof parsed === 'object' && 'data' in parsed
      ? (parsed as { data?: unknown }).data
      : parsed;

  if (typeof root === 'string') {
    return resolveExternalImportBundleItems(root, platformId, messages);
  }

  if (Array.isArray(root)) {
    if (root.length === 0) {
      throw new Error(messages.noItems);
    }
    return root;
  }

  if (!root || typeof root !== 'object') {
    throw new Error(messages.empty);
  }

  const provider = (root as { provider?: unknown }).provider;
  if (typeof provider === 'string' && provider.trim() && provider.trim() !== platformId) {
    throw new Error(messages.providerMismatch);
  }

  const items = (root as { items?: unknown }).items;
  if (Array.isArray(items) && items.length > 0) {
    return items;
  }

View on GitHub (pinned to 1ed8b77992)