{"record":{"id":"fb1f5442895bc1c4","repo":"AykutSarac/jsoncrack.com","slug":"err","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/www/src/features/editor/FullscreenDropzone.tsx","lineNumber":25,"sourceCode":"import useFile from \"../../store/useFile\";\n\nexport const FullscreenDropzone = () => {\n  const setContents = useFile(state => state.setContents);\n\n  return (\n    <Dropzone.FullScreen\n      maxFiles={1}\n      accept={[\"application/json\", \"application/x-yaml\", \"text/csv\", \"application/xml\"]}\n      onReject={files => toast.error(`Unable to load file ${files[0].file.name}`)}\n      onDrop={async e => {\n        try {\n          const fileContent = await e[0].text();\n          let fileExtension = e[0].name.split(\".\").pop() as FileFormat | undefined;\n          if (!fileExtension) fileExtension = FileFormat.JSON;\n          setContents({ contents: fileContent, format: fileExtension, hasChanges: false });\n        } catch (err) {\n          toast.error(\"An error occurred while reading the file.\");\n          console.error(err);\n        }\n      }}\n    >\n      <Group\n        justify=\"center\"\n        ta=\"center\"\n        align=\"center\"\n        gap=\"xl\"\n        h=\"100vh\"\n        style={{ pointerEvents: \"none\" }}\n      >\n        <Dropzone.Accept>\n          <VscFiles size={100} />\n          <Text fz=\"h1\" fw={500} mt=\"lg\">\n            Upload to JSON Crack\n          </Text>\n          <Text fz=\"lg\" c=\"dimmed\" mt=\"sm\">\n            (Max file size: 300 KB)","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/AykutSarac/jsoncrack.com/blob/3c9af69e23c635356293b6b28cf4cd0af10d1059/apps/www/src/features/editor/FullscreenDropzone.tsx#L7-L43","documentation":"The catch fires when reading a dropped file via e[0].text() fails, or when setContents subsequently throws during format conversion. File-read failures are rare and usually indicate the file was locked/moved between drop and read, or the browser denied access. The toast tells the user the read failed.","triggerScenarios":"Dropping a file then the OS locks or removes it before text() resolves; dropping a directory/folder on a browser that exposes it as an unreadable entry; setContents throwing because content exceeds internal limits or fails format conversion.","commonSituations":"Dropping a 0-byte file; dropping from a network share that disconnects mid-read; large file where text() allocation fails; extension cast producing a FileFormat that contentToJson cannot parse.","solutions":["Check e[0].size > 0 before reading.","Enforce the 300KB size limit in onDrop as well as relying on onReject.","Validate the inferred extension against the FileFormat enum before casting.","Surface err.message in the toast for diagnosability."],"exampleFix":"// before\nconst fileContent = await e[0].text();\nlet fileExtension = e[0].name.split(\".\").pop() as FileFormat | undefined;\n\n// after\nif (e[0].size === 0) {\n  return toast.error(\"The selected file is empty.\");\n}\nconst fileContent = await e[0].text();\nconst ext = e[0].name.split(\".\").pop();\nconst fileExtension = isFileFormat(ext) ? ext : FileFormat.JSON;","handlingStrategy":"validation","validationCode":"function isReadableFile(file: { size: number; name: string }): boolean {\n  return file.size > 0 && file.size <= 300 * 1024;\n}","typeGuard":"function isFileFormat(value: unknown): value is FileFormat {\n  return typeof value === \"string\" && Object.values(FileFormat).includes(value as FileFormat);\n}","tryCatchPattern":"onDrop={async e => {\n  if (!isReadableFile(e[0])) {\n    toast.error(\"File is empty or exceeds 300 KB.\");\n    return;\n  }\n  try {\n    const fileContent = await e[0].text();\n    const ext = e[0].name.split(\".\").pop();\n    setContents({ contents: fileContent, format: isFileFormat(ext) ? ext : FileFormat.JSON, hasChanges: false });\n  } catch (err) {\n    toast.error(\"An error occurred while reading the file.\");\n    console.error(err);\n  }\n}}","preventionTips":["Enforce the 300KB limit in onDrop as well as onReject — onReject only fires for MIME mismatches, not oversize.","Reject 0-byte files explicitly so the user gets a precise message.","Validate the inferred extension against the FileFormat enum before casting."],"tags":["file-upload","drag-and-drop","dropzone"],"backgroundTag":null,"analyzedSha":"3c9af69e23c635356293b6b28cf4cd0af10d1059","analyzedAt":"2026-08-12T19:00:27.891Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}