{"record":{"id":"8dc8ff98e7be56c6","repo":"slymnoyann/hey-1","slug":"some-attachments-failed-to-upload","errorCode":null,"errorMessage":"Some attachments failed to upload","messagePattern":"Some attachments failed to upload","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/hooks/useUploadAttachments.tsx","lineNumber":40,"sourceCode":"      setIsUploading(true);\n\n      const files = Array.from(attachments);\n      const compressedFiles = await compressFiles(files);\n\n      if (!compressedFiles.every(validateFileSize)) {\n        setIsUploading(false);\n        return [];\n      }\n\n      const previewAttachments = createPreviewAttachments(compressedFiles);\n      const attachmentIds = previewAttachments.map(({ id }) => id as string);\n\n      addAttachments(previewAttachments);\n\n      try {\n        const uploaded = await uploadToIPFS(compressedFiles);\n        if (uploaded.length !== previewAttachments.length) {\n          throw new Error(\"Some attachments failed to upload\");\n        }\n\n        const result = uploaded.map((file, index) => ({\n          ...previewAttachments[index],\n          mimeType: file.mimeType,\n          uri: file.uri\n        }));\n\n        updateAttachments(result);\n        setIsUploading(false);\n\n        return result;\n      } catch {\n        toast.error(\"Something went wrong while uploading!\");\n        removeAttachments(attachmentIds);\n        setIsUploading(false);\n        return [];\n      }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/slymnoyann/hey-1/blob/88c8f9d55340d57a37846ff72f55c2c604e3a566/src/hooks/useUploadAttachments.tsx#L22-L58","documentation":"Thrown in useUploadAttachments after uploadToIPFS returns fewer uploaded entries than the previewAttachments prepared for upload. The count mismatch means one or more files never made it through the IPFS pinning/upload service, so attaching them by index would misalign mimeTypes and uris.","triggerScenarios":"uploadToIPFS silently drops items on per-file failure (partial batch failure), the service returns 4xx/5xx for some files, a client-side size-limit rejection skips files, or a timeout aborts part of a parallel upload batch.","commonSituations":"Flaky IPFS gateway/pinning service (web3.storage, Pinata, etc.) during batch uploads; rate limits kicking in mid-batch; oversized images where compression fails and the item is skipped; API token quota exhausted after N uploads.","solutions":["Retry the failed upload (or only the missing files) — transient IPFS/service failures are the most common cause","Inspect uploadToIPFS to confirm whether it swallows per-file errors; log which indices are missing instead of failing the whole batch","Check service quota/rate limits and API key validity if failures are consistent","Validate file sizes/types before upload so bad items are rejected up front with a clear message"],"exampleFix":"// before\nconst uploaded = await uploadToIPFS(compressedFiles);\nif (uploaded.length !== previewAttachments.length) {\n  throw new Error(\"Some attachments failed to upload\");\n}\n\n// after: retry once, then report specifics\nlet uploaded = await uploadToIPFS(compressedFiles);\nif (uploaded.length !== compressedFiles.length) {\n  uploaded = await uploadToIPFS(compressedFiles);\n}\nif (uploaded.length !== compressedFiles.length) {\n  throw new Error(`Only ${uploaded.length}/${compressedFiles.length} attachments uploaded`);\n}","handlingStrategy":"retry","validationCode":"const validFiles = compressedFiles.filter(\n  (f) => f.file.size > 0 && f.file.type\n);\nif (validFiles.length !== compressedFiles.length) {\n  // drop/reject invalid files before upload so counts can't mismatch silently\n}","typeGuard":"const isUploadResultComplete = (\n  uploaded: unknown[],\n  expected: number\n): uploaded is { uri: string; mimeType: string }[] =>\n  uploaded.length === expected && uploaded.every((u) => Boolean(u && (u as any).uri));","tryCatchPattern":"try {\n  await uploadAttachments(files);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Some attachments failed to upload\") {\n    await sleep(2000);\n    return uploadAttachments(files); // one retry for transient IPFS failures\n  }\n  throw e;\n}","preventionTips":["Retry transient IPFS failures once with backoff before surfacing the error","Log which indices failed rather than comparing only lengths","Pre-validate file size/type and monitor pinning-service quotas and rate limits"],"tags":["ipfs","upload","batch","partial-failure"],"backgroundTag":"ipfs-upload-partial-failure","analyzedSha":"88c8f9d55340d57a37846ff72f55c2c604e3a566","analyzedAt":"2026-08-28T16:20:43.640Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}