juanfont/headscale · error
getting working directory: %w
Error message
getting working directory: %w
What it means
Returned by `createGoTestContainer` when `os.Getwd()` fails while resolving the repo path to bind-mount into the test container. This is an OS-level error (not Docker's): the process's current working directory was deleted or is otherwise unreadable. The cwd is needed to compute `findProjectRoot(pwd)` for the source mount.
Source
Thrown at cmd/hi/docker.go:227
if config.TestPattern != "" {
cmd = append(cmd, "-run", config.TestPattern)
}
if config.FailFast {
cmd = append(cmd, "-failfast")
}
cmd = append(cmd, "-timeout", config.Timeout.String())
cmd = append(cmd, "-v")
return cmd
}
// createGoTestContainer creates a Docker container configured for running integration tests.
func createGoTestContainer(ctx context.Context, cli *client.Client, config *RunConfig, containerName, logsDir string, goTestCmd []string) (container.CreateResponse, error) {
pwd, err := os.Getwd()
if err != nil {
return container.CreateResponse{}, fmt.Errorf("getting working directory: %w", err)
}
projectRoot := findProjectRoot(pwd)
runID := dockertestutil.ExtractRunIDFromContainerName(containerName)
env := []string{
fmt.Sprintf("HEADSCALE_INTEGRATION_POSTGRES=%d", boolToInt(config.UsePostgres)),
"HEADSCALE_INTEGRATION_RUN_ID=" + runID,
}
// Pass through CI environment variable for CI detection
if ci := os.Getenv("CI"); ci != "" {
env = append(env, "CI="+ci)
}
// Pass through all HEADSCALE_INTEGRATION_* environment variables
for _, e := range os.Environ() {View on GitHub (pinned to 565fd254d0)
Solutions
- Re-run from a directory that exists and is stable for the whole test (repo root).
- In CI, ensure workspace cleanup steps cannot race test execution.
- Check `pwd` works in the same shell before invoking.
Defensive patterns
Strategy: validation
Validate before calling
// verify cwd is readable before launching the runner
if wd, err := os.Getwd(); err != nil || wd == "" {
return fmt.Errorf("invalid working directory: %v", err)
} Try / catch
if err := runDockerTest(ctx, config); err != nil {
if strings.Contains(err.Error(), "getting working directory") {
// restart the process from the repo root; the old cwd was deleted
}
} Prevention
- Invoke hi from the repository root.
- In CI, never let workspace cleanup race a running job.
- Avoid running from ephemeral temp directories.
When it happens
Trigger: Starting `hi run` from a directory that is then deleted before this call; running the binary with a cwd on an unmounted/network filesystem that returns an error; extremely unusual containerized CI where cwd is invalid.
Common situations: Running `hi` from a repo clone that gets removed/replaced mid-session (e.g. CI workspace cleanup racing the job); deleted scratch directories; FUSE mounts returning EIO.
Related errors
- getting absolute path for logs directory: %w
- creating directory failed with permission error
- creating temp dir: %w
- writing config: %w
- dumping config: %w
AI-assisted analysis of juanfont/headscale@565fd254d0 (2026-08-15).
Data as JSON: /api/errors/1e30208e2fad57c6.
Report an issue: GitHub.