{"record":{"id":"f6041bda570e6876","repo":"yorukot/superfile","slug":"failed-to-create-destination-directory-w","errorCode":null,"errorMessage":"failed to create destination directory: %w","messagePattern":"failed to create destination directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":94,"sourceCode":"\n// copyElement handles copying of both files and directories\nfunc copyElement(src, dst string) error {\n\tsrcInfo, err := os.Stat(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat source: %w\", err)\n\t}\n\n\tif srcInfo.IsDir() {\n\t\treturn copyDir(src, dst, srcInfo)\n\t}\n\treturn copyFile(src, dst, srcInfo)\n}\n\n// copyDir recursively copies a directory\nfunc copyDir(src, dst string, srcInfo os.FileInfo) error {\n\terr := os.MkdirAll(dst, srcInfo.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination directory: %w\", err)\n\t}\n\n\tentries, err := os.ReadDir(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read source directory: %w\", err)\n\t}\n\n\tfor _, entry := range entries {\n\t\tsrcPath := filepath.Join(src, entry.Name())\n\t\tdstPath := filepath.Join(dst, entry.Name())\n\n\t\tentryInfo, err := entry.Info()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to get entry info: %w\", err)\n\t\t}\n\n\t\tif entryInfo.IsDir() {\n\t\t\terr = copyDir(srcPath, dstPath, entryInfo)","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L76-L112","documentation":"copyDir creates the destination directory with os.MkdirAll(dst, srcInfo.Mode()); failure is wrapped as 'failed to create destination directory'. This surfaces OS-level errors like missing parent directories that cannot be created, permission denied, or ENOSPC.","triggerScenarios":"copyElement -> copyDir where os.MkdirAll(dst) fails: dst's parent doesn't exist and can't be created (EACCES/EROFS), dst exists as a regular file, or the filesystem is full/read-only.","commonSituations":"Pasting into a destination where a same-named file (not dir) exists; destination on a read-only or full volume; missing write permission on the parent directory; deep destination path on a mount that is unavailable.","solutions":["Ensure the destination parent exists and is writable (mkdir -p, chown/chmod).","Remove or rename a non-directory entry already occupying dst.","Check the destination filesystem is not read-only or full (mount, df -h).","Pick a different destination path if the name collides."],"exampleFix":"// before\nmoveElement(src, \"/backup/dest\") // /backup/dest is a regular file\n// after\nrm /backup/dest            // or choose another name\nmoveElement(src, \"/backup/dest\")","handlingStrategy":"validation","validationCode":"if st, err := os.Lstat(dst); err == nil && !st.IsDir() {\n    return fmt.Errorf(\"destination %s exists and is not a directory\", dst)\n}\nparent := filepath.Dir(dst)\nif st, err := os.Stat(parent); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"destination parent %s missing or invalid\", parent)\n}\n// check writability\nf, err := os.CreateTemp(parent, \".probe\")\nif err != nil { return fmt.Errorf(\"parent not writable: %w\", err) }\nf.Close(); os.Remove(f.Name())","typeGuard":"func canCreateDir(dst string) bool {\n    if st, err := os.Lstat(dst); err == nil && !st.IsDir() { return false }\n    p := filepath.Dir(dst)\n    f, err := os.CreateTemp(p, \".probe\")\n    if err != nil { return false }\n    f.Close(); os.Remove(f.Name())\n    return true\n}","tryCatchPattern":"if err := copyElement(srcDir, dstDir); err != nil {\n    if strings.Contains(err.Error(), \"failed to create destination directory\") {\n        log.Errorf(\"Cannot create %s: %v\", dstDir, err)\n        return proposeAlternativeDestination(srcDir)\n    }\n    return err\n}","preventionTips":["Check for a non-directory name collision at the destination before copying.","Verify the destination volume is mounted read-write and has free space.","Create parent directories yourself with explicit, audited permissions.","Prefer deriving destinations with filepath.Join over manual string building."],"tags":["filesystem","copy","directory","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}