jlcodes99/cockpit-tools · error

[AccountGroups] Group ${index} has an invalid id

Error message

[AccountGroups] Group ${index} has an invalid id

What it means

Validation in parseGroups: the group at the reported index has an id that is not a non-empty string (missing, non-string, or whitespace-only). The id is the primary key used to reference groups, so the entry is unusable and the whole file load fails fast.

Source

Thrown at src/services/accountGroupService.ts:65

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

    return {
      ...group,
      id: group.id,
      name: group.name,
      accountIds: [...group.accountIds],
      // Keep older files without createdAt readable without treating them as
      // an empty data set.
      createdAt: typeof group.createdAt === 'number' ? group.createdAt : 0,
    } as AccountGroup;
  });

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Edit the groups file and give the offending group a non-empty string id (e.g. a UUID)
  2. Remove the broken group entry if it is no longer needed
  3. Add a save-side check so groups are never persisted without a valid id
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/services/accountGroupService.ts:65 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/a72378af78f45289. Report an issue: GitHub.