{"record":{"id":"8fa4314e69cbd461","repo":"gofr-dev/gofr","slug":"failed-to-create-writer","errorCode":null,"errorMessage":"failed to create writer","messagePattern":"failed to create writer","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/ftp/storage_adapter.go","lineNumber":26,"sourceCode":"\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\n}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/storage_adapter.go#L8-L44","documentation":"errFailedToCreateWriter is returned when the FTP storage adapter cannot open an STOR/APPE upload session for an object (NewWriter/Close path on the writer). It wraps the underlying goftp error that occurred while initiating the transfer. It indicates the server refused or failed to start the write operation.","triggerScenarios":"Calling NewWriter (or Create) on the FTP filesystem when the remote directory does not exist, permissions deny upload, the data connection cannot be opened, or the connection has dropped.","commonSituations":"Uploading to a path whose parent directory was never created; FTP user lacks write permission on the target directory; passive-mode firewall blocking the data channel; server hit disk quota or connection limit.","solutions":["Verify the target directory exists and create it (MkdirAll) before creating the writer","Check the FTP user's write permissions on the remote directory","Confirm the underlying FTP connection is alive; reconnect via Connect if it dropped","Inspect the wrapped error (errors.Unwrap) for the raw server reply to pinpoint the cause"],"exampleFix":"// before\nw, err := fs.NewWriter(ctx, \"uploads/data.csv\", nil) // uploads/ may not exist\n// after\n_ = fs.MkdirAll(ctx, \"uploads\")\nw, err := fs.NewWriter(ctx, \"uploads/data.csv\", nil)\nif err != nil { return fmt.Errorf(\"create writer: %w\", err) }","handlingStrategy":"try-catch","validationCode":"// ensure parent dir exists and connection is up before writing\nif err := fs.MkdirAll(ctx, filepath.Dir(objectName)); err != nil { return err }\nif err := fs.TestConnection(ctx); err != nil { return err }","typeGuard":"func isCreateWriterError(err error) bool { return errors.Is(err, ftp.ErrFailedToCreateWriter) }","tryCatchPattern":"w, err := fs.NewWriter(ctx, name, nil)\nif err != nil {\n    if errors.Is(err, ftp.ErrFailedToCreateWriter) {\n        // check dir/permissions/reconnect, then retry once with a new writer\n    }\n    return err\n}","preventionTips":["Create remote directories before uploading","Grant the FTP user write permission on upload directories","Validate connectivity (Connect/TestConnection) before batch uploads","Log errors.Unwrap(err) to capture the raw FTP server reply"],"tags":["ftp","io","object-storage"],"backgroundTag":"ftp-write-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}