vxcontrol/pentagi · warning

file name is required

Error message

file name is required

What it means

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.

Source

Thrown at backend/pkg/flowfiles/files.go:124

	parts := strings.SplitN(cleaned, string(filepath.Separator), 2)
	if parts[0] != UploadsDirName && parts[0] != ContainerDirName && parts[0] != ResourcesDirName {
		return "", fmt.Errorf("path must start with '%s', '%s', or '%s'", UploadsDirName, ContainerDirName, ResourcesDirName)
	}

	flowDataDir := FlowDataDir(dataDir, flowID)
	absPath := filepath.Join(flowDataDir, cleaned)
	if !IsWithinDir(absPath, flowDataDir) {
		return "", fmt.Errorf("path escapes the flow data directory")
	}

	return absPath, nil
}

func SanitizeFileName(fileName string) (string, error) {
	trimmedName := strings.TrimSpace(fileName)
	if trimmedName == "" {
		return "", fmt.Errorf("file name is required")
	}

	normalizedName := strings.ReplaceAll(trimmedName, "\\", "/")
	cleanName := path.Base(path.Clean("/" + normalizedName))

	return validatePathComponent(cleanName)
}

func SanitizeContainerCachePath(containerPath string) (string, error) {
	trimmedPath := strings.TrimSpace(containerPath)
	if trimmedPath == "" {
		return "", fmt.Errorf("path is required")
	}

	normalizedPath := strings.ReplaceAll(trimmedPath, "\\", "/")
	cleanPath := strings.TrimPrefix(path.Clean("/"+normalizedPath), "/")
	if cleanPath == "." || cleanPath == "" {
		return "", fmt.Errorf("invalid path")

View on GitHub (pinned to ea665308ba)

Solutions

  1. Set a filename on the client before uploading (or generate one like 'upload-<timestamp>')
  2. Skip/normalize empty-filename parts server-side before calling SanitizeFileName
  3. Return a 400 to the client asking for a non-empty name
  4. Validate the name is non-empty in the request handler before reaching this function

Example fix

// before
name, _ := sanitizeFileName(part.FileName)
// after
if strings.TrimSpace(part.FileName) == "" {
    part.FileName = fmt.Sprintf("upload-%d", time.Now().UnixNano())
}
name, err := sanitizeFileName(part.FileName)
Defensive patterns

Strategy: validation

Validate before calling

if strings.TrimSpace(fileName) == "" {
    return errors.New("file name is required")
}

Type guard

func hasFileName(name string) bool { return strings.TrimSpace(name) != "" }

Try / catch

name, err := flowfiles.SanitizeFileName(fileName)
if err != nil && strings.Contains(err.Error(), "file name is required") {
    http.Error(w, "file name is required", http.StatusBadRequest)
    return
} else if err != nil {
    return err
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/dffc96b1378e3f7a. Report an issue: GitHub.