{"record":{"id":"06ad6353c183c817","repo":"AykutSarac/jsoncrack.com","slug":"error-message","errorCode":null,"errorMessage":"error.message","messagePattern":"error\\.message","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/www/src/features/modals/JPathModal/index.tsx","lineNumber":25,"sourceCode":"import { VscLinkExternal } from \"react-icons/vsc\";\nimport useFile from \"../../../store/useFile\";\nimport useJson from \"../../../store/useJson\";\n\nexport const JPathModal = ({ opened, onClose }: ModalProps) => {\n  const getJson = useJson(state => state.getJson);\n  const setContents = useFile(state => state.setContents);\n  const [query, setQuery] = React.useState(\"\");\n\n  const evaluteJsonPath = () => {\n    try {\n      const json = getJson();\n      const result = JSONPath({ path: query, json: JSON.parse(json) });\n\n      setContents({ contents: JSON.stringify(result, null, 2) });\n      gaEvent(\"run_json_path\");\n      onClose();\n    } catch (error) {\n      if (error instanceof Error) toast.error(error.message);\n    }\n  };\n\n  return (\n    <Modal title=\"JSON Path\" size=\"lg\" opened={opened} onClose={onClose} centered>\n      <Stack>\n        <Text fz=\"sm\">\n          JsonPath expressions always refer to a JSON structure in the same way as XPath expression\n          are used in combination with an XML document. The &quot;root member object&quot; in\n          JsonPath is always referred to as $ regardless if it is an object or array.\n          <br />\n          <Anchor\n            fz=\"sm\"\n            target=\"_blank\"\n            href=\"https://docs.oracle.com/cd/E60058_01/PDF/8.0.8.x/8.0.8.0.0/PMF_HTML/JsonPath_Expressions.htm\"\n            rel=\"noopener noreferrer\"\n          >\n            Read documentation. <VscLinkExternal />","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/www/src/features/modals/JPathModal/index.tsx#L7-L43","documentation":"In JPathModal.evaluteJsonPath, the catch surfaces the thrown error's message directly as a toast. The try runs getJson() (current editor JSON), JSON.parse(json), then jsonpath-plus JSONPath({ path: query, json }). Any failure — invalid JSON in the editor or an invalid JSONPath expression — is shown to the user via error.message. There is no fallback string; an empty/garbled thrown message would produce an empty toast.","triggerScenarios":"Typing an invalid JSONPath query (e.g. `$.#`, malformed brackets `$.[`, unclosed filter `$..[?(@.price>`), or running the query when the editor content is not valid JSON (JSON.parse throws).","commonSituations":"User experimentation with JSONPath syntax; running a path against partially-edited/invalid JSON; quoting/bracket mistakes in filter expressions.","solutions":["Validate the editor content is parseable JSON before enabling Run (or pre-check with JSON.parse).","Validate the JSONPath query syntax against a known-good expression or a linter.","Provide example queries in the modal to reduce syntax errors.","Guard against non-Error throws so the toast is never empty."],"exampleFix":"// before\n} catch (error) {\n  if (error instanceof Error) toast.error(error.message);\n}\n\n// after — never show an empty message\n} catch (error) {\n  toast.error(error instanceof Error && error.message ? error.message : \"Invalid JSONPath query or JSON.\");\n}","handlingStrategy":"validation","validationCode":"// Validate JSON and JSONPath syntax before running\nexport function canRunJsonPath(json: string, query: string): boolean {\n  try { JSON.parse(json); return typeof query === \"string\" && query.trim().length > 0; }\n  catch { return false; }\n}","typeGuard":"// Ensure the thrown value carries a usable message\nexport function hasMessage(e: unknown): e is Error {\n  return e instanceof Error && typeof e.message === \"string\" && e.message.length > 0;\n}","tryCatchPattern":"// Never show an empty toast\n} catch (error) {\n  toast.error(hasMessage(error) ? error.message : \"Invalid JSONPath query or JSON.\");\n}","preventionTips":["Validate the editor JSON parses before enabling Run.","Provide example JSONPath queries in the modal.","Guard against non-Error throws so the toast is never blank."],"tags":["jsonpath","json","query","modal","parsing"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}