{"record":{"id":"fa2d40d881db73af","repo":"twentyhq/twenty","slug":"failed-to-upload-file-filenameforerror-err","errorCode":null,"errorMessage":"Failed to upload file \"${fileNameForError}\": ${errorMessage}","messagePattern":"Failed to upload file \"(.+?)\": (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useUploadFilesFieldFile.ts","lineNumber":39,"sourceCode":"      const fileName = file.name;\n      enqueueSuccessSnackBar({\n        message: t`File \"${fileName}\" uploaded successfully`,\n      });\n\n      return {\n        fileId: uploadedFile.id,\n        label: file.name,\n        extension: DEFAULT_VALUE_BEFORE_SERVER_RESPONSE,\n        url: DEFAULT_VALUE_BEFORE_SERVER_RESPONSE,\n      };\n    } catch (error) {\n      const fileNameForError = file.name;\n      const errorMessage = String(error);\n      enqueueErrorSnackBar({\n        message: t`Failed to upload \"${fileNameForError}\"`,\n      });\n\n      throw new Error(\n        t`Failed to upload file \"${fileNameForError}\": ${errorMessage}`,\n      );\n    }\n  };\n\n  return { uploadFile };\n};\n","sourceCodeStart":21,"sourceCodeEnd":47,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/hooks/useUploadFilesFieldFile.ts#L21-L47","documentation":"Thrown by useUploadFilesFieldFile (useUploadFilesFieldFile.ts:30-44) when the underlying file upload call rejects. The hook first enqueues an error snack bar with a user-facing message, then re-throws a more detailed Error containing the file name and String(error). This surfaces the failure to the form so the field can mark itself errored.","triggerScenarios":"Calling uploadFile(file) where the awaited upload promise rejects (network failure, 4xx/5xx from the upload endpoint, file too large, unsupported type, auth failure).","commonSituations":"File exceeds server size limit; network interruption during upload; expired auth token on the upload endpoint; unsupported MIME type; CORS on the upload endpoint; disk/storage failure server-side.","solutions":["Inspect the inner errorMessage (String(error)) — it carries the underlying cause.","Validate file size/type on the client before uploading.","Confirm the upload endpoint is reachable and auth token is valid.","Add retry with backoff for transient network failures."],"exampleFix":"// before\n<input type=\"file\" onChange={(e) => uploadFile(e.target.files?.[0]!)} />\n// after\nconst file = e.target.files?.[0];\nif (file && file.size <= MAX_SIZE && ALLOWED_TYPES.has(file.type)) {\n  uploadFile(file);\n} else {\n  enqueueErrorSnackBar({ message: t`File not allowed` });\n}","handlingStrategy":"try-catch","validationCode":"const MAX_SIZE = 10 * 1024 * 1024;\nconst ALLOWED_TYPES = new Set(['image/png', 'image/jpeg', 'application/pdf']);\nif (file.size > MAX_SIZE || !ALLOWED_TYPES.has(file.type)) {\n  enqueueErrorSnackBar({ message: t`File too large or unsupported type` });\n  return;\n}\nawait uploadFile(file);","typeGuard":"const isAllowedFile = (f: File): boolean =>\n  f.size <= MAX_SIZE && ALLOWED_TYPES.has(f.type);","tryCatchPattern":"try {\n  await uploadFile(file);\n} catch (err) {\n  // hook already enqueues a snack bar; mark the field errored here\n  setFieldError(fieldName, t`Upload failed`);\n}","preventionTips":["Validate file size and type before uploading.","Confirm upload endpoint auth and reachability.","Add retry for transient network errors.","Show upload progress so users do not resubmit mid-upload."],"tags":["frontend","file-upload","object-record","field"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}