{"record":{"id":"1f637ad4dcea3807","repo":"gofr-dev/gofr","slug":"ftp-config-is-nil","errorCode":null,"errorMessage":"FTP config is nil","messagePattern":"FTP config is nil","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/ftp/storage_adapter.go","lineNumber":19,"sourceCode":"package ftp\n\nimport (\n\t\"bytes\"\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io\"\n\t\"path\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/jlaffaye/ftp\"\n\t\"gofr.dev/pkg/gofr/datasource/file\"\n)\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 {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/storage_adapter.go#L1-L37","documentation":"errFTPConfigNil is returned by the FTP storage adapter's Connect when its internal *Config pointer is nil. The adapter cannot dial an FTP server without connection parameters, so it refuses to start. It is a programming/configuration error, not a transient network condition.","triggerScenarios":"Calling Connect() on a storageAdapter created with a nil cfg (e.g. ftp.New(nil) paths where config was never populated, or manual adapter construction with &storageAdapter{cfg: nil}).","commonSituations":"Passing nil to constructors and assuming defaults; zero-value struct usage before initialization; DI frameworks injecting a nil config when no FTP config is present in the environment.","solutions":["Provide a non-nil *ftp.Config with host/port before connecting.","Guard at startup: if cfg == nil, fail fast with a clear configuration error instead of reaching Connect().","Use ftp.New(&ftp.Config{...}) so defaults (DialTimeout, location) are applied."],"exampleFix":"// before\nadapter := &ftp.StorageAdapter{} // cfg nil\nadapter.Connect()\n// after\nadapter := ftp.New(&ftp.Config{Host: host, Port: 21})","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    return nil, fmt.Errorf(\"ftp config required: set host and port\")\n}\nfs := ftp.New(cfg)","typeGuard":"func hasFTPConfig(c *ftp.Config) bool { return c != nil && c.Host != \"\" }","tryCatchPattern":"// Connect is async and logs; guard construction instead\nif cfg == nil {\n    log.Fatal(\"FTP config is nil; refusing to start FTP filesystem\")\n}\nfs := ftp.New(cfg)","preventionTips":["Never pass nil to ftp.New; always supply a populated Config.","Validate config presence at application startup, not at connect time.","If config is optional in your app, skip creating the FTP filesystem entirely when absent."],"tags":["go","ftp","nil-config","initialization"],"backgroundTag":"nil-config","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}