juanfont/headscale · error

getting absolute path for logs directory: %w

Error message

getting absolute path for logs directory: %w

What it means

Returned by runTestContainer when filepath.Abs on the per-run logs directory (LogsDir/<runID>) fails. filepath.Abs almost only fails when os.Getwd fails — the process's working directory was deleted or is unreadable. The relative logs path itself is irrelevant; the failure is about the current working directory.

Source

Thrown at cmd/hi/docker.go:57

	cli, err := createDockerClient(ctx)
	if err != nil {
		return fmt.Errorf("creating Docker client: %w", err)
	}
	defer cli.Close()

	runID := dockertestutil.GenerateRunID()
	containerName := "headscale-test-suite-" + runID
	logsDir := filepath.Join(config.LogsDir, runID)

	if config.Verbose {
		log.Printf("Run ID: %s", runID)
		log.Printf("Container name: %s", containerName)
		log.Printf("Logs directory: %s", logsDir)
	}

	absLogsDir, err := filepath.Abs(logsDir)
	if err != nil {
		return fmt.Errorf("getting absolute path for logs directory: %w", err)
	}

	const dirPerm = 0o755
	if err := os.MkdirAll(absLogsDir, dirPerm); err != nil { //nolint:noinlineerr
		return fmt.Errorf("creating logs directory: %w", err)
	}

	if config.CleanBefore {
		if config.Verbose {
			log.Printf("Running pre-test cleanup...")
		}

		err := cleanupBeforeTest(ctx)
		if err != nil && config.Verbose {
			log.Printf("Warning: pre-test cleanup failed: %v", err)
		}
	}

View on GitHub (pinned to 565fd254d0)

Solutions

  1. cd into an existing directory and re-run the command
  2. Restore or recreate the deleted working directory
  3. Check for unreadable parent directories on the cwd path

Example fix

# before (shell sits in a deleted directory)
go run ./cmd/hi run TestACL   # getting absolute path for logs directory: ...

# after
cd /path/to/headscale
go run ./cmd/hi run TestACL
Defensive patterns

Strategy: validation

Validate before calling

// Verify the cwd exists before launching hi.
if _, err := os.Getwd(); err != nil {
	fmt.Fprintln(os.Stderr, "working directory is gone — cd to a valid dir")
	os.Exit(1)
}

Try / catch

Not retriable as-is: re-run the command from an existing directory. In Go, check os.Getwd error explicitly when resolving relative paths.

Prevention

When it happens

Trigger: Starting an `hi run` from a directory that was deleted (e.g. a removed temp/worktree dir) while the shell still sits in it; cwd with unreadable parents; exotic environments where getwd(2) fails.

Common situations: Running hi from a git worktree that another process removed; scripts that cd into build dirs later deleted; sandboxed environments blocking getcwd.

Related errors


AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15). Data as JSON: /api/errors/f6b7f9f7a1621c9b. Report an issue: GitHub.