gofr-dev/gofr · error
object name is empty
Error message
object name is empty
What it means
errEmptyObjectName is returned by NewReader, NewRangeReader, NewWriter, StatObject and DeleteObject when the object (file) name argument is the empty string. The adapter validates names up front to avoid issuing malformed FTP commands (e.g. RETR "").
Source
Thrown at pkg/gofr/datasource/file/ftp/storage_adapter.go:21
import (
"bytes"
"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 usernameView on GitHub (pinned to 187eb24962)
Solutions
- Validate name != "" (and strings.TrimSpace) before calling the adapter operation.
- Fix the upstream source of the name (env var, path parse, request parameter).
- Check tests: TestStorageAdapter_NewReader covers this case — mirror it in your own validation.
Example fix
// before
reader, err := adapter.NewReader(ctx, name) // name == ""
// after
if strings.TrimSpace(name) == "" {
return nil, fmt.Errorf("object name required")
}
reader, err := adapter.NewReader(ctx, name) Defensive patterns
Strategy: validation
Validate before calling
func ensureName(name string) error {
if strings.TrimSpace(name) == "" {
return fmt.Errorf("object name must be non-empty")
}
return nil
} Type guard
func validObjectName(name string) bool { return strings.TrimSpace(name) != "" } Try / catch
if err := ensureName(name); err != nil { return err }
reader, err := adapter.NewReader(ctx, name)
if errors.Is(err, errEmptyObjectName) { return fmt.Errorf("missing file name: %w", err) } Prevention
- Trim and validate file names at the API boundary before storage calls.
- Avoid string splitting that can yield empty final segments.
- Fail fast with a clear 400-level message when a client omits a file name.
When it happens
Trigger: Passing "" as the name to any object operation; deriving a file name from an empty variable, missing path segment, or untrimmed input.
Common situations: Empty path variables from config/env; string splitting producing an empty final segment; loops over listings using an uninitialized name variable.
Related errors
- invalid FTP configuration: host and port are required
- invalid FTP provider
- invalid offset: must be >= 0
- source and destination names cannot be empty
- source and destination are the same
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/f5d3b7e99c6f2944.
Report an issue: GitHub.