{"record":{"id":"c1f4b62d8ba29b1e","repo":"gofr-dev/gofr","slug":"failed-to-create-reader-c1f4b6","errorCode":null,"errorMessage":"failed to create reader","messagePattern":"failed to create reader","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/ftp/storage_adapter.go","lineNumber":25,"sourceCode":"\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 {\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","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/storage_adapter.go#L7-L43","documentation":"errFailedToCreateReader is returned by NewReader and NewRangeReader when the adapter cannot open a read stream for the object — typically the underlying ftp client's Retr/RetrFrom call failed. The sentinel may wrap the transport-level cause, which usually indicates the file does not exist, permissions deny access, or the connection is broken.","triggerScenarios":"NewReader/NewRangeReader on a nonexistent remote file, a file without read permission, or while the FTP connection has dropped mid-operation.","commonSituations":"Typos or wrong remote dir in the path; file deleted between listing and read; passive-mode/firewall issues killing the data connection; server-side 550 (file unavailable) responses.","solutions":["Verify the object exists (StatObject) and the path/remote dir is correct before reading.","Check FTP credentials and file permissions on the server.","Reconnect (fs.Connect) if the connection dropped, then retry the read.","Inspect the wrapped cause (errors.Unwrap / provider logs) for the server's FTP response code."],"exampleFix":"// before\nr, err := adapter.NewReader(ctx, name)\n// after\nif _, err := adapter.StatObject(ctx, name); err != nil {\n    return nil, fmt.Errorf(\"object %q unavailable: %w\", name, err)\n}\nr, err := adapter.NewReader(ctx, name)","handlingStrategy":"retry","validationCode":"if _, err := adapter.StatObject(ctx, name); err != nil {\n    return fmt.Errorf(\"object %q not available for read: %w\", name, err)\n}\nif !fsConnected() { reconnectFTP() }","typeGuard":null,"tryCatchPattern":"r, err := adapter.NewReader(ctx, name)\nif errors.Is(err, errFailedToCreateReader) {\n    reconnectFTP()\n    r, err = adapter.NewReader(ctx, name) // one retry after reconnect\n    if err != nil { return fmt.Errorf(\"read %q failed after retry: %w\", name, err) }\n}","preventionTips":["Stat the object before reading to catch missing files early.","Keep the FTP connection alive with health checks and auto-reconnect.","Verify remote dir and permissions; 550 responses are the usual cause.","Distinguish permanent (not found) from transient (connection) failures before retrying."],"tags":["go","ftp","io","network"],"backgroundTag":"failed-to-create-reader","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}