{"record":{"id":"6fcc76420380bb52","repo":"gofr-dev/gofr","slug":"incorrect-file-type","errorCode":null,"errorMessage":"incorrect file type","messagePattern":"incorrect file type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/file/s3/fs.go","lineNumber":26,"sourceCode":"\t\"mime\"\n\t\"os\"\n\t\"path\"\n\t\"time\"\n\n\t\"github.com/aws/aws-sdk-go-v2/aws\"\n\tawsConfig \"github.com/aws/aws-sdk-go-v2/config\"\n\t\"github.com/aws/aws-sdk-go-v2/credentials\"\n\t\"github.com/aws/aws-sdk-go-v2/service/s3\"\n\tfile \"gofr.dev/pkg/gofr/datasource/file\"\n)\n\nconst (\n\ttypeFile      = \"file\"\n\ttypeDirectory = \"directory\"\n)\n\nvar (\n\terrIncorrectFileType = errors.New(\"incorrect file type\")\n)\n\n// client struct embeds the *s3.Client.\ntype client struct {\n\t*s3.Client\n}\n\ntype FileSystem struct {\n\ts3File    S3File\n\tconn      s3Client\n\tpresigner s3Presigner\n\tconfig    *Config\n\tlogger    Logger\n\tmetrics   Metrics\n}\n\n// Config represents the s3 configuration.\ntype Config struct {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/file/s3/fs.go#L8-L44","documentation":"errIncorrectFileType is the sentinel returned by (*FileSystem).Rename when the old and new names are not of the same type — specifically when a file is renamed with a new name whose extension differs from the old one. S3 has no real rename, so the implementation copies + deletes, and it refuses cross-type renames rather than guessing intent.","triggerScenarios":"Calling Rename(oldname, newname) where path.Ext(oldname) != path.Ext(newname) and the old name is a file (non-empty extension), e.g. Rename(\"bucket/a.txt\", \"bucket/a.json\").","commonSituations":"Renaming a file and accidentally changing its extension; code that rewrites names with a different suffix; converting formats via 'rename' instead of copy+transform.","solutions":["Keep the same extension in the new name: strip only the base name portion.","If a format/type change is really intended, copy the object to the new key with the new extension via your own CopyObject call instead of Rename.","If the extension is semantically meaningless in your bucket layout, name files without extensions consistently (note: an empty extension is treated as a directory here)."],"exampleFix":"// before\nfs.Rename(\"bucket/report.txt\", \"bucket/report-final.csv\") // error\n// after\nfs.Rename(\"bucket/report.txt\", \"bucket/report-final.txt\")","handlingStrategy":"validation","validationCode":"func canRename(old, new string) bool {\n    return path.Ext(old) == path.Ext(new)\n}\n// guard:\nif !canRename(oldName, newName) { /* fix newName before calling Rename */ }","typeGuard":null,"tryCatchPattern":"if err := fs.Rename(old, new); err != nil {\n    if strings.Contains(err.Error(), \"incorrect file type\") {\n        // keep the original extension and retry\n    }\n    return err\n}","preventionTips":["Build new names by replacing only the base name, never the extension.","Treat empty extension as directory in this API — don't mix file/dir renames.","Do real format conversion with copy+transform, not Rename.","Validate extension equality before calling Rename."],"tags":["rename","s3","validation","gofr"],"backgroundTag":"type-mismatch","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}