{"record":{"id":"bd0459e5b3e9c1ad","repo":"toeverything/AFFiNE","slug":"notreadableerror","errorCode":"NotReadableError","errorMessage":"File could not be read","messagePattern":"File could not be read","errorType":"exception","errorClass":"DOMException","httpStatus":null,"severity":"error","filePath":"blocksuite/affine/shared/src/utils/file/filesys.ts","lineNumber":198,"sourceCode":"function sleep(ms: number) {\n  return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nexport async function snapshotFile(file: File, relativePath?: string) {\n  let bytes: Uint8Array | null = null;\n  for (let attempt = 0; attempt < 3; attempt++) {\n    try {\n      bytes = new Uint8Array(await file.arrayBuffer());\n      break;\n    } catch (error) {\n      if (!isNotReadableError(error) || attempt === 2) {\n        throw error;\n      }\n      await sleep(100 * (attempt + 1));\n    }\n  }\n  if (!bytes) {\n    throw new DOMException('File could not be read', 'NotReadableError');\n  }\n  const snapshot = new File([copyToArrayBuffer(bytes)], file.name, {\n    type: file.type,\n    lastModified: file.lastModified,\n  });\n  const path = relativePath ?? file.webkitRelativePath;\n  if (path) {\n    Object.defineProperty(snapshot, 'webkitRelativePath', {\n      value: path,\n      writable: false,\n    });\n  }\n  return snapshot;\n}\n\nexport async function snapshotFiles(files: File[]) {\n  const results = await Promise.allSettled(\n    files.map(file => snapshotFile(file))","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/b4c8548c09da21b2898443559a5b846f0ccf5dd8/blocksuite/affine/shared/src/utils/file/filesys.ts#L180-L216","documentation":"snapshotFile retries file.arrayBuffer() three times for transient NotReadable errors and this DOMException fires only if all attempts failed or the loop exited without bytes, i.e. the File handle stayed unreadable (e.g. file moved/deleted on disk mid-read).","triggerScenarios":"Thrown at blocksuite/affine/shared/src/utils/file/filesys.ts:198 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the File/Blob object is still valid and not already consumed by a previous read; re-obtain the file handle before reading.","Check that the file actually exists and is readable (permissions, path) before calling file.arrayBuffer() or FileReader.readAsArrayBuffer.","Handle the DOMException from the underlying FileReader by surfacing its message to the user so they can retry or pick a different file."],"exampleFix":"async function readFile(file: File): Promise<ArrayBuffer> {\n  if (!file || file.size === 0) throw new Error('Empty file selected');\n  try {\n    return await file.arrayBuffer();\n  } catch (e) {\n    throw new Error(`File could not be read: ${(e as Error).message}`);\n  }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b4c8548c09da21b2898443559a5b846f0ccf5dd8","analyzedAt":"2026-08-18T21:16:52.546Z","contentChangedAt":"2026-08-18T21:16:52.546Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}