{"record":{"id":"b107a4ca960df602","repo":"gofr-dev/gofr","slug":"invalid-ftp-configuration-host-and-port-are-requi","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/fs.go","lineNumber":13,"sourceCode":"package ftp\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"gofr.dev/pkg/gofr/datasource/file\"\n)\n\nvar (\n\terrInvalidConfig   = errors.New(\"invalid FTP configuration: host and port are required\")\n\terrInvalidProvider = errors.New(\"invalid FTP provider\")\n)\n\nconst defaultTimeout = 10 * time.Second\n\ntype fileSystem struct {\n\t*file.CommonFileSystem\n}\n\n// New creates and validates a new FTP file system.\n// Returns error if connection fails or configuration is invalid.\nfunc New(config *Config) file.FileSystemProvider {\n\tif config == nil {\n\t\tconfig = &Config{}\n\t}\n\n\t// Set default dial timeout if not specified\n\tif config.DialTimeout == 0 {","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/fs.go#L1-L31","documentation":"errInvalidConfig is returned by the FTP filesystem's validateConfig when the Config lacks a host or port, which are mandatory to reach an FTP server. It signals the FTP filesystem cannot be used until host and port are supplied in the Config struct.","triggerScenarios":"Calling Connect() (or validateConfig) on ftp.New(&ftp.Config{}) with an empty Host, or a Config where both host and port are unset.","commonSituations":"Forgetting to populate host/port from environment variables; constructing Config{} with only a remote dir; nil Config defaulting to an empty struct; config struct fields renamed in a version upgrade.","solutions":["Set Config.Host and Config.Port (port defaults to 21 only for display; validation still requires them) before calling Connect().","Load host/port from environment or config file and fail fast at startup if empty.","Check the error via errors.Is(err, ftp.ErrInvalidConfig) and skip/skip-connect rather than retrying."],"exampleFix":"// before\nfs := ftp.New(&ftp.Config{RemoteDir: \"/data\"})\nfs.Connect()\n// after\nfs := ftp.New(&ftp.Config{Host: \"ftp.example.com\", Port: 21, RemoteDir: \"/data\"})\nfs.Connect()","handlingStrategy":"validation","validationCode":"func validFTPConfig(c *ftp.Config) bool {\n    if c == nil { return false }\n    return c.Host != \"\" && c.Port != 0\n}","typeGuard":null,"tryCatchPattern":"fs := ftp.New(cfg)\nif err := fs.ValidateConfig(); err != nil { // or errors.Is on Connect logs\n    log.Fatalf(\"ftp config invalid: %v\", err)\n}","preventionTips":["Fail fast at startup if FTP_HOST/FTP_PORT env vars are missing.","Centralize config construction in one constructor that always sets Host and Port.","Write a unit test asserting New/Connect errors on empty host/port.","Remember port defaults to 21 for display but validation still requires explicit values."],"tags":["go","ftp","configuration","validation"],"backgroundTag":"missing-required-config","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}