{"record":{"id":"184ecf2a1f176714","repo":"AykutSarac/jsoncrack.com","slug":"invalid-schema","errorCode":null,"errorMessage":"Invalid Schema","messagePattern":"Invalid Schema","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/www/src/features/modals/SchemaModal/index.tsx","lineNumber":43,"sourceCode":"          },\n        },\n        required: [\"id\"],\n      },\n      null,\n      2\n    )\n  );\n\n  const onApply = () => {\n    try {\n      const parsedSchema = JSON.parse(schema);\n      setJsonSchema(parsedSchema);\n\n      gaEvent(\"apply_json_schema\");\n      toast.success(\"Applied schema!\");\n      onClose();\n    } catch {\n      toast.error(\"Invalid Schema\");\n    }\n  };\n\n  const onClear = () => {\n    setJsonSchema(null);\n    setSchema(\"\");\n    toast(\"Disabled JSON Schema\");\n    onClose();\n  };\n\n  return (\n    <Modal title=\"JSON Schema\" size=\"lg\" opened={opened} onClose={onClose} centered>\n      <Stack>\n        <Text fz=\"sm\">Any validation failures are shown at the bottom toolbar of pane.</Text>\n        <Anchor\n          fz=\"sm\"\n          target=\"_blank\"\n          href=\"https://niem.github.io/json/sample-schema/\"","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/www/src/features/modals/SchemaModal/index.tsx#L25-L61","documentation":"Toast shown by the JSON Schema modal when the schema text cannot be parsed as JSON. onApply calls JSON.parse(schema) inside try/catch; any SyntaxError (or thrown primitive) routes to the catch with the generic 'Invalid Schema' message. The schema is not applied on failure.","triggerScenarios":"Typing a schema with trailing commas, unquoted keys, unclosed braces, single quotes, comments, or any non-strict-JSON content in the textarea, then clicking Apply.","commonSituations":"Pasting a schema written in JSON5/JS object literal syntax; an incomplete edit; copying a schema that uses // comments; a copy-paste that drops a brace.","solutions":["Validate the schema with a JSON linter in the editor before applying.","Run JSON.parse on the schema string in the console to get the exact SyntaxError position.","Surface the caught SyntaxError message/position to the user instead of the generic text.","Provide inline JSON validation feedback in the textarea (e.g. a parse-error marker)."],"exampleFix":"// before\n} catch {\n  toast.error(\"Invalid Schema\");\n}\n\n// after — show the parser's position\n} catch (err) {\n  toast.error(err instanceof SyntaxError ? `Invalid Schema: ${err.message}` : \"Invalid Schema\");\n}","handlingStrategy":"validation","validationCode":"// Validate schema parses before applying\nexport function tryParseSchema(text: string): { ok: true; value: unknown } | { ok: false; error: SyntaxError } {\n  try { return { ok: true, value: JSON.parse(text) }; }\n  catch (e) { return { ok: false, error: e as SyntaxError }; }\n}","typeGuard":"// Narrow the parse outcome\nexport function isSchemaValid(r: ReturnType<typeof tryParseSchema>): r is { ok: true; value: unknown } {\n  return r.ok;\n}","tryCatchPattern":"// Surface the parser's position instead of a generic message\nconst result = tryParseSchema(schema);\nif (!result.ok) {\n  toast.error(`Invalid Schema: ${result.error.message}`);\n  return;\n}\nsetJsonSchema(result.value);","preventionTips":["Run a JSON linter in the schema textarea.","Catch and display the SyntaxError position to the user.","Disable Apply until the schema parses."],"tags":["json-schema","json","validation","modal"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}