{"record":{"id":"c246a5c0f24f96aa","repo":"vxcontrol/pentagi","slug":"flowfiles-alreadyexists","errorCode":"FlowFiles.AlreadyExists","errorMessage":"flow file '%s' already exists","messagePattern":"flow file '(.+?)' already exists","errorType":"http","errorClass":null,"httpStatus":409,"severity":"error","filePath":"backend/pkg/server/services/flow_files.go","lineNumber":237,"sourceCode":"\t\t\terr = fmt.Errorf(\"uploaded files total size %d bytes exceeds the maximum allowed size of %d bytes\",\n\t\t\t\ttotalSize, flowfiles.MaxUploadTotalSize)\n\t\t\tlogger.FromContext(c).WithError(err).WithField(\"flow_id\", flowID).Error(\"uploaded files total size too large\")\n\t\t\tresponse.Error(c, response.ErrFlowFilesInvalidRequest, err)\n\t\t\treturn\n\t\t}\n\n\t\tdstPath := filepath.Join(uploadDir, fileName)\n\t\texists, err := flowfiles.LocalEntryExists(dstPath)\n\t\tif err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).WithFields(map[string]any{\n\t\t\t\t\"flow_id\":   flowID,\n\t\t\t\t\"file_name\": fileName,\n\t\t\t}).Error(\"error checking existing uploaded file\")\n\t\t\tresponse.Error(c, response.ErrInternal, err)\n\t\t\treturn\n\t\t}\n\t\tif exists {\n\t\t\terr = fmt.Errorf(\"flow file '%s' already exists\", fileName)\n\t\t\tlogger.FromContext(c).WithError(err).WithFields(map[string]any{\n\t\t\t\t\"flow_id\":   flowID,\n\t\t\t\t\"file_name\": fileName,\n\t\t\t}).Error(\"uploaded file already exists\")\n\t\t\tresponse.Error(c, response.ErrFlowFilesAlreadyExists, err)\n\t\t\treturn\n\t\t}\n\n\t\tpending = append(pending, pendingUpload{fileName: fileName, dstPath: dstPath})\n\t}\n\n\t// All files passed validation — write temporary files first to avoid partial commits on copy errors.\n\tfor i := range pending {\n\t\ttmpPath, err := flowfiles.SaveUploadedFileToTemp(fileHeaders[i], uploadDir)\n\t\tif err != nil {\n\t\t\tlogger.FromContext(c).WithError(err).WithFields(map[string]any{\n\t\t\t\t\"flow_id\":   flowID,\n\t\t\t\t\"file_name\": pending[i].fileName,","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/server/services/flow_files.go#L219-L255","documentation":"Before saving, UploadFlowFiles checks whether a flow file with the same name already exists for the flow (via the flowfiles service). If it does, the upload aborts with FlowFiles.AlreadyExists rather than silently overwriting the stored object.","triggerScenarios":"POSTing an upload whose file name matches an existing file in the same flow's data directory — e.g. re-running a job that produces 'report.txt' or 'nmap-output.xml'.","commonSituations":"Re-running a scan that regenerates identically-named output files; retrying a partially-failed upload; two clients uploading concurrently with default names.","solutions":["Rename the file before upload so the name is unique within the flow (e.g. add a timestamp).","Delete the existing flow file first (DeleteFlowFile) and retry the upload.","Make the producer include a run-id/nonce in generated file names to guarantee uniqueness.","Handle the AlreadyExists response in the client to prompt the user for overwrite/rename."],"exampleFix":"// before\nawait uploadFlowFile(flowID, new File(blob, 'report.txt'));\n// after\nawait uploadFlowFile(flowID, new File(blob, `report-${Date.now()}.txt`));","handlingStrategy":"try-catch","validationCode":"const existing = await listFlowFiles(flowID);\nconst clash = existing.some(f => f.name === newName);\nif (clash) newName = uniquifyName(newName);","typeGuard":null,"tryCatchPattern":"try { await uploadFlowFile(flowID, file); } catch (e) { if (isAlreadyExists(e)) { await deleteFlowFile(flowID, file.name); await uploadFlowFile(flowID, file); } else throw e; }","preventionTips":["Generate unique file names (timestamp/run-id) in producers","Check the flow's file listing before uploading","Handle AlreadyExists explicitly with rename-or-overwrite UX"],"tags":["file-upload","conflict","duplicate"],"backgroundTag":"file-already-exists","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}