{"record":{"id":"dffc96b1378e3f7a","repo":"vxcontrol/pentagi","slug":"file-name-is-required","errorCode":null,"errorMessage":"file name is required","messagePattern":"file name is required","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"backend/pkg/flowfiles/files.go","lineNumber":124,"sourceCode":"\n\tparts := strings.SplitN(cleaned, string(filepath.Separator), 2)\n\tif parts[0] != UploadsDirName && parts[0] != ContainerDirName && parts[0] != ResourcesDirName {\n\t\treturn \"\", fmt.Errorf(\"path must start with '%s', '%s', or '%s'\", UploadsDirName, ContainerDirName, ResourcesDirName)\n\t}\n\n\tflowDataDir := FlowDataDir(dataDir, flowID)\n\tabsPath := filepath.Join(flowDataDir, cleaned)\n\tif !IsWithinDir(absPath, flowDataDir) {\n\t\treturn \"\", fmt.Errorf(\"path escapes the flow data directory\")\n\t}\n\n\treturn absPath, nil\n}\n\nfunc SanitizeFileName(fileName string) (string, error) {\n\ttrimmedName := strings.TrimSpace(fileName)\n\tif trimmedName == \"\" {\n\t\treturn \"\", fmt.Errorf(\"file name is required\")\n\t}\n\n\tnormalizedName := strings.ReplaceAll(trimmedName, \"\\\\\", \"/\")\n\tcleanName := path.Base(path.Clean(\"/\" + normalizedName))\n\n\treturn validatePathComponent(cleanName)\n}\n\nfunc SanitizeContainerCachePath(containerPath string) (string, error) {\n\ttrimmedPath := strings.TrimSpace(containerPath)\n\tif trimmedPath == \"\" {\n\t\treturn \"\", fmt.Errorf(\"path is required\")\n\t}\n\n\tnormalizedPath := strings.ReplaceAll(trimmedPath, \"\\\\\", \"/\")\n\tcleanPath := strings.TrimPrefix(path.Clean(\"/\"+normalizedPath), \"/\")\n\tif cleanPath == \".\" || cleanPath == \"\" {\n\t\treturn \"\", fmt.Errorf(\"invalid path\")","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/flowfiles/files.go#L106-L142","documentation":"Returned by SanitizeFileName (backend/pkg/flowfiles/files.go) when the supplied file name is empty or only whitespace. Callers should validate user/tool-provided file names before calling; provide a non-empty name.","triggerScenarios":"Calling SanitizeFileName with \"\", whitespace-only input, or a filename field that was never set on an upload request (e.g. multipart part without filename, empty form value).","commonSituations":"Multipart uploads where the client omitted the filename; frontend sending an empty name for a blob without one; bulk upload loops where one entry has an empty name and aborts the whole batch.","solutions":["Set a filename on the client before uploading (or generate one like 'upload-<timestamp>')","Skip/normalize empty-filename parts server-side before calling SanitizeFileName","Return a 400 to the client asking for a non-empty name","Validate the name is non-empty in the request handler before reaching this function"],"exampleFix":"// before\nname, _ := sanitizeFileName(part.FileName)\n// after\nif strings.TrimSpace(part.FileName) == \"\" {\n    part.FileName = fmt.Sprintf(\"upload-%d\", time.Now().UnixNano())\n}\nname, err := sanitizeFileName(part.FileName)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(fileName) == \"\" {\n    return errors.New(\"file name is required\")\n}","typeGuard":"func hasFileName(name string) bool { return strings.TrimSpace(name) != \"\" }","tryCatchPattern":"name, err := flowfiles.SanitizeFileName(fileName)\nif err != nil && strings.Contains(err.Error(), \"file name is required\") {\n    http.Error(w, \"file name is required\", http.StatusBadRequest)\n    return\n} else if err != nil {\n    return err\n}","preventionTips":["Always set the filename on multipart parts when uploading","Generate a default name client-side when the browser provides none","Validate filename presence in the request handler before sanitization","Handle per-file errors in bulk uploads without aborting the entire batch"],"tags":["validation","filename","upload"],"backgroundTag":"missing-filename","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}