{"record":{"id":"c4c8fe1339fd0426","repo":"gofr-dev/gofr","slug":"failed-to-delete-object-c4c8fe","errorCode":null,"errorMessage":"failed to delete object","messagePattern":"failed to delete object","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/ftp/storage_adapter.go","lineNumber":29,"sourceCode":"\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}\n\n// storageAdapter adapts FTP client to implement file.StorageProvider.\ntype storageAdapter struct {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/ftp/storage_adapter.go#L11-L47","documentation":"errFailedToDeleteObject is returned by DeleteObject when the DELE (or directory removal) command fails after the object was confirmed to exist. It wraps the server-side error, meaning the server refused or could not complete the deletion.","triggerScenarios":"Calling DeleteObject on a path that exists but cannot be removed: read-only permissions, the path is a non-empty directory, or the server rejects the DELE/RMD command.","commonSituations":"FTP account lacks delete permission; attempting to delete a directory that still contains entries; file locked by another upload session; object vanished between stat and delete (race).","solutions":["Check the FTP user has write/delete permission on the parent directory","For directories, empty them (delete children first) before removal","Inspect the wrapped error for the server reply code to confirm the cause","Retry if the object may have been concurrently removed by another process"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// check permissions/emptiness before delete\ninfo, err := fs.StatObject(ctx, name)\nif err != nil { return err }\n_ = info // verify it is a deletable file, and dir is empty if removing a directory","typeGuard":"func isDeleteError(err error) bool { return errors.Is(err, ftp.ErrFailedToDeleteObject) }","tryCatchPattern":"err := fs.DeleteObject(ctx, name)\nif errors.Is(err, ftp.ErrFailedToDeleteObject) {\n    // inspect wrapped server reply; check perms or non-empty dir\n    return fmt.Errorf(\"delete %s: %w\", name, err)\n}","preventionTips":["Grant delete permission to the service FTP account on target directories","Delete directory children before removing the directory itself","Handle races: re-stat after failure to see if the object already vanished","Avoid deleting from directories other processes write to concurrently"],"tags":["ftp","delete","permissions"],"backgroundTag":"ftp-delete-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}