yorukot/superfile · error

failed to get absolute path of the first path: %w

Error message

failed to get absolute path of the first path: %w

What it means

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.

Source

Thrown at src/internal/file_operations.go:21

import (
	"fmt"
	"io"
	"log/slog"
	"os"
	"path/filepath"
	"runtime"
	"strings"

	"github.com/yorukot/superfile/src/internal/ui/processbar"
	"github.com/yorukot/superfile/src/pkg/utils"
)

// isSamePartition checks if two paths are on the same filesystem partition
func isSamePartition(path1, path2 string) (bool, error) {
	// Get the absolute path to handle relative paths
	absPath1, err := filepath.Abs(path1)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the first path: %w", err)
	}

	absPath2, err := filepath.Abs(path2)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the second path: %w", err)
	}

	if runtime.GOOS == utils.OsWindows {
		// On Windows, we can check if both paths are on the same drive (same letter)
		drive1 := getDriveLetter(absPath1)
		drive2 := getDriveLetter(absPath2)
		return drive1 == drive2, nil
	}

	// For Unix-like systems, we use the same path to check the root partition
	return filepath.VolumeName(absPath1) == filepath.VolumeName(absPath2), nil
}

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Ensure the process's current working directory exists (cd to a valid dir before invoking).
  2. Pass absolute source/destination paths so filepath.Abs has no work to do.
  3. Recreate the deleted working directory.
  4. Check disk/permission state if Getwd fails system-wide.

Example fix

// before
moveElement("../downloads/file.txt", "/tmp/dest") // cwd deleted
// after
moveElement("/home/user/downloads/file.txt", "/tmp/dest")
Defensive patterns

Strategy: validation

Validate before calling

if !filepath.IsAbs(src) {
    cwd, err := os.Getwd()
    if err != nil {
        return fmt.Errorf("cannot resolve relative src: %w", err)
    }
    src = filepath.Join(cwd, src)
}

Type guard

func isAbsPath(p string) bool { return filepath.IsAbs(p) }

Try / catch

_, err := internal.MoveElementTyped(src, dst) // any API wrapping moveElement
if err != nil && strings.Contains(err.Error(), "failed to check partitions") {
    if werr := errors.Unwrap(errors.Unwrap(err)); werr != nil {
        log.Errorf("partition check failed: %v — retrying with absolute paths", werr)
        return retryWithAbsPaths(src, dst)
    }
}

Prevention

When it happens

Trigger: moveElement or pasteDir call isSamePartition with a relative path1 while os.Getwd fails (current working directory removed or unreadable).

Common situations: 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.

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/4eb86e5bed39ed82. Report an issue: GitHub.