jlcodes99/cockpit-tools · error

messages.empty

Error message

messages.empty

What it means

The bundle unwrapped to something that is neither a string, an array, nor a non-null object (e.g. number, boolean, or null) — there is no structure to extract accounts from, so messages.empty is thrown (line 417).

Source

Thrown at src/hooks/useProviderAccountsPage.ts:417

  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;
  }

  if (platformId === 'codex' && isCodexDirectImportItem(root)) {
    return [root];
  }

  if (!Array.isArray(items) || items.length === 0) {
    throw new Error(messages.noItems);

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Check the pasted/exported content actually contains an object or array of accounts
  2. Re-export from the source; ensure the payload is the account bundle, not a scalar
  3. If double-encoded, decode once more before importing

Example fix

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

Strategy: type-guard

Validate before calling

const root: unknown = JSON.parse(content);
if (!root || typeof root !== 'object') throw new Error('Bundle must be a JSON object or array');

Type guard

const isBundleObject = (v: unknown): v is Record<string, unknown> =>
  !!v && typeof v === 'object' && !Array.isArray(v);

Try / catch

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

Prevention

When it happens

Trigger: JSON parses to a primitive or null at the root after envelope unwrapping: e.g. the file contains just 42, true, null, or a quoted plain string that recursively unwraps to a primitive.

Common situations: Pasting a bare token value or number instead of a bundle; an export that serialized null; double-encoded JSON where the innermost value is a scalar; wrong file selected.

Related errors


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