jlcodes99/cockpit-tools · error

[AccountGroups] Invalid JSON: ${String(error)}

Error message

[AccountGroups] Invalid JSON: ${String(error)}

What it means

Guard inside parseGroups: JSON.parse of the raw account-groups file failed, so the stored data is corrupt (truncated write, manual edit, or encoding damage). The SyntaxError is rewrapped as a single Error carrying the original message. parseGroups is strict by design — corrupt storage fails fast instead of silently returning an empty group list.

Source

Thrown at src/services/accountGroupService.ts:51

    () => undefined,
    () => undefined,
  );
  return next;
}

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

View on GitHub (pinned to 1ed8b77992)

Solutions

  1. Restore the account-groups file from a WebDAV/local backup
  2. If no backup exists, fix or remove the corrupt JSON file so the service can recreate defaults
  3. Check for interrupted writes (crash during save) and confirm the persistence layer writes atomically
Defensive patterns

Strategy: try-catch

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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