{"record":{"id":"8414d215d040ab14","repo":"yorukot/superfile","slug":"failed-to-copy-w","errorCode":null,"errorMessage":"failed to copy: %w","messagePattern":"failed to copy: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":66,"sourceCode":"func moveElement(src, dst string) error {\n\t// Check if source and destination are on the same partition\n\tsameDev, err := isSamePartition(src, dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to check partitions: %w\", err)\n\t}\n\n\t// If on the same partition, attempt to rename (which will use the same inode)\n\tif sameDev {\n\t\tif err = os.Rename(src, dst); err == nil {\n\t\t\treturn nil\n\t\t}\n\t\t// If rename fails, fall back to copy+delete\n\t}\n\n\t// If on different partitions or rename failed, fall back to copy+delete\n\terr = copyElement(src, dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to copy: %w\", err)\n\t}\n\n\terr = os.RemoveAll(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to remove source after copy: %w\", err)\n\t}\n\n\treturn nil\n}\n\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() {","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L48-L84","documentation":"When the source and destination are on different partitions (or os.Rename failed), moveElement falls back to copying via copyElement and then deleting the source; this error wraps any copy failure. The root cause (permission, disk full, missing source) is in the wrapped error chain.","triggerScenarios":"moveElement(src, dst) where copyElement fails: os.Stat fails on src, directory creation or file copy fails on dst (ENOENT parent, EACCES, ENOSPC).","commonSituations":"Moving across drives to a full destination disk; destination directory not writable; source disappeared between the rename attempt and the copy; copying a directory containing unreadable entries.","solutions":["Inspect the wrapped error for the true cause (stat vs write failure).","Check free space on the destination (df -h) — ENOSPC is common on cross-partition moves.","Verify the destination directory exists and is writable.","Confirm the source still exists and is readable before moving."],"exampleFix":"// before\nmoveElement(\"/home/data\", \"/mnt/full-disk/data\") // ENOSPC\n// after\n// free space or choose another destination\nmoveElement(\"/home/data\", \"/mnt/other/data\")","handlingStrategy":"try-catch","validationCode":"srcInfo, err := os.Stat(src)\nif err != nil { return fmt.Errorf(\"source missing: %w\", err) }\nif st, err := os.Stat(filepath.Dir(dst)); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"destination parent must be an existing writable dir\")\n}\n// optional: free-space check via syscall.Statfs on dst volume","typeGuard":"func isWritableDir(p string) bool {\n    st, err := os.Stat(p)\n    return err == nil && st.IsDir()\n}","tryCatchPattern":"if err := moveElement(src, dst); err != nil {\n    if strings.Contains(err.Error(), \"failed to copy\") {\n        log.Errorf(\"cross-partition move failed: %v\", err)\n        // keep source intact; surface ENOSPC/EACCES to the user\n        return err\n    }\n    return err\n}","preventionTips":["Check destination free space before large cross-partition moves.","Ensure the destination directory exists and is writable beforehand.","Verify the source exists immediately before initiating the move.","For very large trees, consider copy-with-progress so failures are resumable."],"tags":["filesystem","copy","move"],"backgroundTag":"copy-failed","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}