gofr-dev/gofr · error

source and destination names cannot be empty

Error message

source and destination names cannot be empty

What it means

errEmptySourceOrDest is returned by CopyObject when either the source or destination object name is the empty string. Both names are required to issue the FTP copy operation; the adapter validates them before any network call.

Source

Thrown at pkg/gofr/datasource/file/ftp/storage_adapter.go:23

	"context"
	"errors"
	"fmt"
	"io"
	"path"
	"strings"
	"time"

	"github.com/jlaffaye/ftp"
	"gofr.dev/pkg/gofr/datasource/file"
)

var (
	// Storage adapter errors.
	errFTPConfigNil            = errors.New("FTP config is nil")
	errFTPClientNotInitialized = errors.New("FTP client is not initialized")
	errEmptyObjectName         = errors.New("object name is empty")
	errInvalidOffset           = errors.New("invalid offset: must be >= 0")
	errEmptySourceOrDest       = errors.New("source and destination names cannot be empty")
	errSameSourceAndDest       = errors.New("source and destination are the same")
	errFailedToCreateReader    = errors.New("failed to create reader")
	errFailedToCreateWriter    = errors.New("failed to create writer")
	errObjectNotFound          = errors.New("object not found")
	errFailedToGetObjectAttrs  = errors.New("failed to get object attrs")
	errFailedToDeleteObject    = errors.New("failed to delete object")
	errFailedToListObjects     = errors.New("failed to list objects")
	errFailedToListDirectory   = errors.New("failed to list directory")
	errWriterAlreadyClosed     = errors.New("writer already closed")
	errFTPConfigInvalid        = errors.New("invalid FTP configuration: host and port are required")
)

// Config represents the FTP configuration.
type Config struct {
	Host        string        // FTP server hostname
	User        string        // FTP username
	Password    string        // FTP password
	Port        int           // FTP port

View on GitHub (pinned to 187eb24962)

Solutions

  1. Validate both source and destination are non-empty before calling CopyObject.
  2. Populate the missing name from config/request data and fail fast with a clear message if absent.
  3. Trim whitespace to avoid names that are non-empty but blank.

Example fix

// before
err := adapter.CopyObject(ctx, src, dst) // dst == ""
// after
if src == "" || dst == "" {
    return fmt.Errorf("copy requires non-empty source and destination")
}
err := adapter.CopyObject(ctx, src, dst)
Defensive patterns

Strategy: validation

Validate before calling

if src == "" || dst == "" {
    return fmt.Errorf("copy requires both source and destination")
}
if src == dst {
    return nil // or error
}

Type guard

func validCopyArgs(src, dst string) bool { return src != "" && dst != "" && src != dst }

Try / catch

if !validCopyArgs(src, dst) {
    return fmt.Errorf("invalid copy: src=%q dst=%q", src, dst)
}
err := adapter.CopyObject(ctx, src, dst)

Prevention

When it happens

Trigger: Calling CopyObject(ctx, src, dst) with src == "" or dst == "", typically from empty config values, untrimmed inputs, or empty path components.

Common situations: Rename flows where only one of old/new name was populated; template/config missing one of the two paths; splitting full paths and losing a segment.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/b725a0ebadb24792. Report an issue: GitHub.