jlcodes99/cockpit-tools · error

[AccountGroups] Stored data must be a JSON array

Error message

[AccountGroups] Stored data must be a JSON array

What it means

Validation in parseGroups: the stored account-groups file parsed as valid JSON but its root is not an array (e.g. an object or scalar). The persistence contract requires a JSON array of group objects, so any other root shape is rejected as corrupt storage.

Source

Thrown at src/services/accountGroupService.ts:55

}

function cloneGroups(groups: AccountGroup[]): AccountGroup[] {
  return groups.map((group) => ({
    ...group,
    accountIds: [...group.accountIds],
  }));
}

function parseGroups(raw: string): AccountGroup[] {
  let parsed: unknown;
  try {
    parsed = JSON.parse(raw);
  } catch (error) {
    throw new Error(`[AccountGroups] Invalid JSON: ${String(error)}`);
  }

  if (!Array.isArray(parsed)) {
    throw new Error('[AccountGroups] Stored data must be a JSON array');
  }

  const groups = parsed.map((value, index) => {
    if (!value || typeof value !== 'object' || Array.isArray(value)) {
      throw new Error(`[AccountGroups] Invalid group at index ${index}`);
    }

    const group = value as Record<string, unknown>;
    if (typeof group.id !== 'string' || !group.id.trim()) {
      throw new Error(`[AccountGroups] Group ${index} has an invalid id`);
    }
    if (typeof group.name !== 'string') {
      throw new Error(`[AccountGroups] Group ${index} has an invalid name`);
    }
    if (!Array.isArray(group.accountIds) || group.accountIds.some((id) => typeof id !== 'string')) {
      throw new Error(`[AccountGroups] Group ${index} has invalid account ids`);
    }

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Restore the groups file from backup; the root must be a JSON array
  2. If the file was hand-edited, wrap the group entries in an array
  3. Verify the saving side always serializes AccountGroup[] and not a wrapper object
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/services/accountGroupService.ts:55 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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