{"record":{"id":"e3587402eccce395","repo":"jlcodes99/cockpit-tools","slug":"accountgroups-invalid-json-string-error","errorCode":null,"errorMessage":"[AccountGroups] Invalid JSON: ${String(error)}","messagePattern":"\\[AccountGroups\\] Invalid JSON: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/services/accountGroupService.ts","lineNumber":51,"sourceCode":"    () => undefined,\n    () => undefined,\n  );\n  return next;\n}\n\nfunction cloneGroups(groups: AccountGroup[]): AccountGroup[] {\n  return groups.map((group) => ({\n    ...group,\n    accountIds: [...group.accountIds],\n  }));\n}\n\nfunction parseGroups(raw: string): AccountGroup[] {\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(raw);\n  } catch (error) {\n    throw new Error(`[AccountGroups] Invalid JSON: ${String(error)}`);\n  }\n\n  if (!Array.isArray(parsed)) {\n    throw new Error('[AccountGroups] Stored data must be a JSON array');\n  }\n\n  const groups = parsed.map((value, index) => {\n    if (!value || typeof value !== 'object' || Array.isArray(value)) {\n      throw new Error(`[AccountGroups] Invalid group at index ${index}`);\n    }\n\n    const group = value as Record<string, unknown>;\n    if (typeof group.id !== 'string' || !group.id.trim()) {\n      throw new Error(`[AccountGroups] Group ${index} has an invalid id`);\n    }\n    if (typeof group.name !== 'string') {\n      throw new Error(`[AccountGroups] Group ${index} has an invalid name`);\n    }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/jlcodes99/cockpit-tools/blob/1ed8b77992d62ca81fabf744deb0839ad361d5bf/src/services/accountGroupService.ts#L33-L69","documentation":"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.","triggerScenarios":"Thrown at src/services/accountGroupService.ts:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Restore the account-groups file from a WebDAV/local backup","If no backup exists, fix or remove the corrupt JSON file so the service can recreate defaults","Check for interrupted writes (crash during save) and confirm the persistence layer writes atomically"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"1ed8b77992d62ca81fabf744deb0839ad361d5bf","analyzedAt":"2026-09-05T09:51:41.178Z","contentChangedAt":"2026-09-05T09:51:41.178Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}