{"record":{"id":"1e30208e2fad57c6","repo":"juanfont/headscale","slug":"getting-working-directory-w","errorCode":null,"errorMessage":"getting working directory: %w","messagePattern":"getting working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/hi/docker.go","lineNumber":227,"sourceCode":"\tif config.TestPattern != \"\" {\n\t\tcmd = append(cmd, \"-run\", config.TestPattern)\n\t}\n\n\tif config.FailFast {\n\t\tcmd = append(cmd, \"-failfast\")\n\t}\n\n\tcmd = append(cmd, \"-timeout\", config.Timeout.String())\n\tcmd = append(cmd, \"-v\")\n\n\treturn cmd\n}\n\n// createGoTestContainer creates a Docker container configured for running integration tests.\nfunc createGoTestContainer(ctx context.Context, cli *client.Client, config *RunConfig, containerName, logsDir string, goTestCmd []string) (container.CreateResponse, error) {\n\tpwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn container.CreateResponse{}, fmt.Errorf(\"getting working directory: %w\", err)\n\t}\n\n\tprojectRoot := findProjectRoot(pwd)\n\n\trunID := dockertestutil.ExtractRunIDFromContainerName(containerName)\n\n\tenv := []string{\n\t\tfmt.Sprintf(\"HEADSCALE_INTEGRATION_POSTGRES=%d\", boolToInt(config.UsePostgres)),\n\t\t\"HEADSCALE_INTEGRATION_RUN_ID=\" + runID,\n\t}\n\n\t// Pass through CI environment variable for CI detection\n\tif ci := os.Getenv(\"CI\"); ci != \"\" {\n\t\tenv = append(env, \"CI=\"+ci)\n\t}\n\n\t// Pass through all HEADSCALE_INTEGRATION_* environment variables\n\tfor _, e := range os.Environ() {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/juanfont/headscale/blob/565fd254d06c4c7f9a8cad1714a43445c79ba420/cmd/hi/docker.go#L209-L245","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// verify cwd is readable before launching the runner\nif wd, err := os.Getwd(); err != nil || wd == \"\" {\n    return fmt.Errorf(\"invalid working directory: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runDockerTest(ctx, config); err != nil {\n    if strings.Contains(err.Error(), \"getting working directory\") {\n        // restart the process from the repo root; the old cwd was deleted\n    }\n}","preventionTips":["Invoke hi from the repository root.","In CI, never let workspace cleanup race a running job.","Avoid running from ephemeral temp directories."],"tags":["filesystem","os","working-directory","hi-runner"],"backgroundTag":null,"analyzedSha":"565fd254d06c4c7f9a8cad1714a43445c79ba420","analyzedAt":"2026-08-15T13:12:30.133Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}