{"record":{"id":"4eb86e5bed39ed82","repo":"yorukot/superfile","slug":"failed-to-get-absolute-path-of-the-first-path-w","errorCode":null,"errorMessage":"failed to get absolute path of the first path: %w","messagePattern":"failed to get absolute path of the first path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":21,"sourceCode":"import (\n\t\"fmt\"\n\t\"io\"\n\t\"log/slog\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/yorukot/superfile/src/internal/ui/processbar\"\n\t\"github.com/yorukot/superfile/src/pkg/utils\"\n)\n\n// isSamePartition checks if two paths are on the same filesystem partition\nfunc isSamePartition(path1, path2 string) (bool, error) {\n\t// Get the absolute path to handle relative paths\n\tabsPath1, err := filepath.Abs(path1)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to get absolute path of the first path: %w\", err)\n\t}\n\n\tabsPath2, err := filepath.Abs(path2)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to get absolute path of the second path: %w\", err)\n\t}\n\n\tif runtime.GOOS == utils.OsWindows {\n\t\t// On Windows, we can check if both paths are on the same drive (same letter)\n\t\tdrive1 := getDriveLetter(absPath1)\n\t\tdrive2 := getDriveLetter(absPath2)\n\t\treturn drive1 == drive2, nil\n\t}\n\n\t// For Unix-like systems, we use the same path to check the root partition\n\treturn filepath.VolumeName(absPath1) == filepath.VolumeName(absPath2), nil\n}\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L3-L39","documentation":"isSamePartition resolves both paths to absolute form before comparing filesystems; this error wraps a filepath.Abs failure on the first path. filepath.Abs only fails if the process cannot determine the working directory (e.g. it was deleted) for relative input paths.","triggerScenarios":"moveElement or pasteDir call isSamePartition with a relative path1 while os.Getwd fails (current working directory removed or unreadable).","commonSituations":"Running in a directory that was deleted while the process lives (shell in a rm'd dir); running as a service with a stale/removed cwd; race where the cwd is unmounted mid-operation.","solutions":["Ensure the process's current working directory exists (cd to a valid dir before invoking).","Pass absolute source/destination paths so filepath.Abs has no work to do.","Recreate the deleted working directory.","Check disk/permission state if Getwd fails system-wide."],"exampleFix":"// before\nmoveElement(\"../downloads/file.txt\", \"/tmp/dest\") // cwd deleted\n// after\nmoveElement(\"/home/user/downloads/file.txt\", \"/tmp/dest\")","handlingStrategy":"validation","validationCode":"if !filepath.IsAbs(src) {\n    cwd, err := os.Getwd()\n    if err != nil {\n        return fmt.Errorf(\"cannot resolve relative src: %w\", err)\n    }\n    src = filepath.Join(cwd, src)\n}","typeGuard":"func isAbsPath(p string) bool { return filepath.IsAbs(p) }","tryCatchPattern":"_, err := internal.MoveElementTyped(src, dst) // any API wrapping moveElement\nif err != nil && strings.Contains(err.Error(), \"failed to check partitions\") {\n    if werr := errors.Unwrap(errors.Unwrap(err)); werr != nil {\n        log.Errorf(\"partition check failed: %v — retrying with absolute paths\", werr)\n        return retryWithAbsPaths(src, dst)\n    }\n}","preventionTips":["Always pass absolute paths into move/paste operations.","Never assume the process cwd is stable in long-running apps or daemons.","Resolve and cache the cwd at startup if relative paths must be supported.","Restore a valid cwd (os.Chdir(\"/\")) in services after startup."],"tags":["paths","filesystem","go"],"backgroundTag":"working-directory-missing","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}