{"record":{"id":"55322867243341ea","repo":"gofr-dev/gofr","slug":"invalid-ftp-configuration-host-and-port-are-requi-553228","errorCode":null,"errorMessage":"invalid FTP configuration: host and port are required","messagePattern":"invalid FTP configuration: host and port are required","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/ftp/storage_adapter.go","lineNumber":33,"sourceCode":")\n\nvar (\n\t// Storage adapter errors.\n\terrFTPConfigNil            = errors.New(\"FTP config is nil\")\n\terrFTPClientNotInitialized = errors.New(\"FTP client is not initialized\")\n\terrEmptyObjectName         = errors.New(\"object name is empty\")\n\terrInvalidOffset           = errors.New(\"invalid offset: must be >= 0\")\n\terrEmptySourceOrDest       = errors.New(\"source and destination names cannot be empty\")\n\terrSameSourceAndDest       = errors.New(\"source and destination are the same\")\n\terrFailedToCreateReader    = errors.New(\"failed to create reader\")\n\terrFailedToCreateWriter    = errors.New(\"failed to create writer\")\n\terrObjectNotFound          = errors.New(\"object not found\")\n\terrFailedToGetObjectAttrs  = errors.New(\"failed to get object attrs\")\n\terrFailedToDeleteObject    = errors.New(\"failed to delete object\")\n\terrFailedToListObjects     = errors.New(\"failed to list objects\")\n\terrFailedToListDirectory   = errors.New(\"failed to list directory\")\n\terrWriterAlreadyClosed     = errors.New(\"writer already closed\")\n\terrFTPConfigInvalid        = errors.New(\"invalid FTP configuration: host and port are required\")\n)\n\n// Config represents the FTP configuration.\ntype Config struct {\n\tHost        string        // FTP server hostname\n\tUser        string        // FTP username\n\tPassword    string        // FTP password\n\tPort        int           // FTP port\n\tRemoteDir   string        // Remote directory path. Base Path for all FTP Operations.\n\tDialTimeout time.Duration // FTP connection timeout\n}\n\n// storageAdapter adapts FTP client to implement file.StorageProvider.\ntype storageAdapter struct {\n\tcfg  *Config\n\tconn *ftp.ServerConn\n}\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/storage_adapter.go#L15-L51","documentation":"errFTPConfigInvalid is returned by Connect when the Config is missing a Host or Port, which are mandatory for dialing an FTP server. It is a fail-fast validation error raised before any network activity. It indicates a programming or configuration mistake, not a runtime condition.","triggerScenarios":"Calling Connect with a Config whose Host is \"\" or whose Port is 0 — e.g. constructing Config{} without loading values, or environment variables/flags not wired into the struct.","commonSituations":"Missing FTP_HOST/FTP_PORT env vars at deploy time; config struct built with defaults that leave Port zero; YAML/JSON config key typos leaving fields unset.","solutions":["Set Host and Port in the Config before calling Connect","Load values from environment or config file and validate they are non-empty/non-zero","Fail fast at application startup with an explicit validation check on the config","Check config file keys/spelling so values actually populate the struct"],"exampleFix":"// before\ncfg := &ftp.Config{} // Host, Port unset\nfs.Connect(cfg)\n// after\ncfg := &ftp.Config{Host: \"ftp.example.com\", Port: 21, User: u, Password: p}\nif cfg.Host == \"\" || cfg.Port == 0 { return errors.New(\"ftp host/port required\") }\nfs.Connect(cfg)","handlingStrategy":"validation","validationCode":"func validateFTPConfig(cfg *ftp.Config) error {\n    if cfg == nil || cfg.Host == \"\" || cfg.Port == 0 {\n        return errors.New(\"ftp config: host and port are required\")\n    }\n    return nil\n}","typeGuard":"func isConfigInvalid(err error) bool { return errors.Is(err, ftp.ErrFTPConfigInvalid) }","tryCatchPattern":"if err := fs.Connect(cfg); errors.Is(err, ftp.ErrFTPConfigInvalid) {\n    // config bug — do not retry; fix construction of Config\n    return err\n}","preventionTips":["Validate Config (Host non-empty, Port != 0) at application startup","Fail fast with clear messages when env vars for FTP host/port are missing","Use defaults for Port (21) when unset, if appropriate for your deployment","Check config-file key spelling so values actually bind to the struct"],"tags":["ftp","configuration","validation"],"backgroundTag":"missing-config-field","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}