{"record":{"id":"30cba63dfc205ace","repo":"yorukot/superfile","slug":"failed-to-get-entry-info-w","errorCode":null,"errorMessage":"failed to get entry info: %w","messagePattern":"failed to get entry info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":108,"sourceCode":"// 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)\n\t\t} else {\n\t\t\terr = copyFile(srcPath, dstPath, entryInfo)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\n// is an equivalent of \"cp -P\" command\nfunc copyLinkFile(src, dst string) error {\n\ttarget, err := os.Readlink(src)\n\tif err != nil {","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L90-L126","documentation":"copyDir wraps any error returned by os.DirEntry.Info() when it tries to stat an entry inside a directory being recursively copied. The underlying cause (permission, race where the file vanished, broken symlink handling) is preserved via %w. It aborts the recursive copy of the whole directory tree.","triggerScenarios":"Calling copyElement or copyDir on a directory whose contents change between os.ReadDir and entry.Info(), or where the process lacks permission to stat an entry (e.g. a directory requiring root traversal).","commonSituations":"Copying a directory being concurrently modified (build output, log dirs, /tmp churn); copying into a container mount where entries race; permission-restricted source directories.","solutions":["Re-run the copy operation; transient races usually disappear on a second attempt.","Check read/execute permissions on the source directory tree (ls -la, or chmod to add r+x).","Freeze or exclude concurrently-written directories (stop writers, skip build/log dirs) before copying.","If files vanish regularly, wrap the copy in retry logic or copy a consistent snapshot."],"exampleFix":"// before\nerr = copyDir(srcPath, dstPath, entryInfo)\n// after\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOENT) {\n        slog.Warn(\"entry vanished during copy, skipping\", \"path\", srcPath)\n        continue\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight: ensure the tree is traversable\nif info, err := os.Stat(srcDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"invalid source dir %s\", srcDir)\n}","typeGuard":"func isDirEntryStatable(e os.DirEntry) bool {\n    _, err := e.Info()\n    return err == nil\n}","tryCatchPattern":"if err := ops.CopyElement(src, dst); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOENT) {\n        // entry vanished mid-copy: retry or skip\n    } else {\n        return err\n    }\n}","preventionTips":["Don't copy directories that are actively being written (build outputs, logs).","Verify r+x permissions on the source tree before copying.","Retry transient stat failures instead of aborting the whole tree copy."],"tags":["go","filesystem","copy","stat"],"backgroundTag":"path-stat-failed","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}