{"record":{"id":"e2118942d79875fc","repo":"beekeeper-studio/beekeeper-studio","slug":"invalid-json","errorCode":null,"errorMessage":"Invalid JSON","messagePattern":"Invalid JSON","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/studio/src/lib/UserProvidedEnum.ts","lineNumber":9,"sourceCode":"import _ from \"lodash\";\n\nexport class UserProvidedEnum {\n\tname: string;\n\tvariants: { id: string, value: string }[];\n\tconstructor(json: any) {\n\t\tif (json.name == undefined || json.variants == undefined || \n\t\t\t!_.isString(json.name) || !_.isArray(json.variants)) {\n\t\t\tthrow new Error('Invalid JSON');\n\t\t}\n\n\t\tthis.name = json.name;\n\t\tthis.variants = [];\n\n\t\tfor (let i = 0; i < json.variants.length; i++) {\n\t\t\tconst variant = json.variants[i];\n\n\t\t\tif (variant.id != undefined && variant.value != undefined) \n\t\t\t\tthis.variants.push({ id: variant.id, value: variant.value });\n\t\t}\n\n\t\tif (this.variants.length == 0) throw new Error(`Enum ${this.name} does not have any variants`);\n\t}\n\n\t// TODO (day): should probably clean this up for other types\n\tfindMatch(id: string): string {\n\t\tconst variant = this.variants.find((val) => val.id == id);","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/beekeeper-studio/beekeeper-studio/blob/4e3e03e3223b2b71a1af8926d455f533b80af837/apps/studio/src/lib/UserProvidedEnum.ts#L1-L27","documentation":"`UserProvidedEnum` wraps a user-supplied enum definition and validates the raw JSON in its constructor. It throws 'Invalid JSON' when `json` is missing `name` or `variants`, when `name` is not a string, or when `variants` is not an array. This fails fast on malformed enum definitions before they are used elsewhere.","triggerScenarios":"Constructing `new UserProvidedEnum(parsed)` where parsed.name is absent/not a string, parsed.variants is absent or not an array, or the JSON failed to parse and something undefined/null was passed.","commonSituations":"Hand-edited enum JSON files with a typo in a key (e.g. 'variantes'); loading a config saved by an older schema; JSON.parse result wrapped differently ({enum: {...}}); file read returned empty string parsed to null.","solutions":["Validate the object shape before constructing: name is a string, variants is an array","Fix the JSON keys so `name` and `variants` exist at the top level","Check that the file/string parsed successfully (JSON.parse errors) before passing in","Check the source file is the expected enum definition, not another config"],"exampleFix":"// before\nconst e = new UserProvidedEnum(JSON.parse(raw));\n// after\nconst parsed = JSON.parse(raw);\nif (typeof parsed?.name !== 'string' || !Array.isArray(parsed?.variants)) {\n  throw new Error('Enum definition must have string name and variants array');\n}\nconst e = new UserProvidedEnum(parsed);","handlingStrategy":"validation","validationCode":"function isValidEnumJson(json: any): boolean {\n  return !!json && typeof json.name === 'string' && Array.isArray(json.variants);\n}","typeGuard":"function isUserProvidedEnumJson(v: any): v is { name: string; variants: { id: string; value: string }[] } {\n  return typeof v?.name === 'string' && Array.isArray(v?.variants) &&\n    v.variants.every((x: any) => typeof x?.id === 'string' && typeof x?.value === 'string');\n}","tryCatchPattern":"try {\n  const e = new UserProvidedEnum(json);\n} catch (err) {\n  if (err.message === 'Invalid JSON') {\n    console.warn('Malformed enum definition, skipping', json);\n    return null;\n  }\n  throw err;\n}","preventionTips":["Validate JSON schema before constructing domain objects","Keep enum JSON files under schema validation/linting","Handle JSON.parse failures separately from shape errors"],"tags":["validation","json","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"4e3e03e3223b2b71a1af8926d455f533b80af837","analyzedAt":"2026-08-31T23:21:23.379Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}