{"record":{"id":"b4b0cd4aff92c528","repo":"kubernetes/minikube","slug":"getting-current-working-directory-failed","errorCode":null,"errorMessage":"Getting current working directory failed","messagePattern":"Getting current working directory failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/extract/extract.go","lineNumber":39,"sourceCode":"Usage: from the root minikube directory, go run cmd/extract/extract.go\n*/\n\npackage main\n\nimport (\n\t\"os\"\n\t\"strings\"\n\n\t\"k8s.io/minikube/pkg/minikube/extract\"\n)\n\nfunc main() {\n\tpaths := []string{\"cmd\", \"pkg\"}\n\tfunctions := []string{\"translate.T\"}\n\toutDir := \"translations\"\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\tpanic(\"Getting current working directory failed\")\n\t}\n\n\tif strings.Contains(cwd, \"cmd\") {\n\t\tpanic(\"run extract.go from the minikube root directory\")\n\t}\n\n\tif _, err = os.Stat(extract.ErrMapFile); os.IsNotExist(err) {\n\t\tpanic(\"err_map.go doesn't exist\")\n\t}\n\terr = extract.TranslatableStrings(paths, functions, outDir)\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n","sourceCodeStart":21,"sourceCodeEnd":55,"githubUrl":"https://github.com/kubernetes/minikube/blob/a899afc0eb0b122b323c7ea5ba8e31e3b4ca4b8e/cmd/extract/extract.go#L21-L55","documentation":"cmd/extract/extract.go is a maintainer tool that extracts translate.T strings from cmd/ and pkg/ into the translations/ directory. Before doing anything it calls os.Getwd(), and if the Go runtime cannot return the process working directory it panics with 'Getting current working directory failed'. On Linux this almost always means the current directory was deleted while the shell still sat in it (the inode is gone, so getcwd(2) fails). It is an environment failure, not a code bug in minikube itself.","triggerScenarios":"Running `go run cmd/extract/extract.go` from a directory that was removed or renamed out from under the process (common after `git clean -dxf` or deleting a worktree in another terminal); a container/sandbox where the cwd is unlinked or unreadable; on Windows, a cwd with a dropped UNC share.","commonSituations":"A CI job that cds into a temp workspace that a previous cleanup step deleted; a developer whose terminal is inside a directory removed by `git clean`; running the tool from an unmounted or permission-revoked path.","solutions":["Run `pwd` in the same shell; if it errors or shows a stale path, `cd` back into a directory that exists (the minikube repo root).","Re-create or re-clone the workspace if it was deleted, then re-run from the minikube root.","If in CI, ensure the cleanup step that removes the workspace runs after, not before, the extract tool.","Optionally wrap the cause in the panic (fmt.Errorf with %w) so the next failure shows the underlying errno."],"exampleFix":"// before\ncwd, err := os.Getwd()\nif err != nil {\n    panic(\"Getting current working directory failed\")\n}\n\n// after\ncwd, err := os.Getwd()\nif err != nil {\n    panic(fmt.Errorf(\"getting current working directory failed: %w\", err))\n}","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(\".\"); err != nil {\n    log.Fatalf(\"working directory is not accessible: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Fatalf(\"extract failed: %v\", r)\n    }\n}()\ncwd, err := os.Getwd()\nif err != nil {\n    panic(fmt.Errorf(\"getting current working directory failed: %w\", err))\n}","preventionTips":["Run `pwd` (or check the terminal prompt) before invoking the tool; a stale prompt after a `git clean` means the directory is gone.","In CI, invoke the tool with an explicit working directory (e.g. `dir:` step) instead of relying on an inherited cwd.","Wrap panics with fmt.Errorf and %w so getcwd errno details survive into the panic message.","Avoid running long-lived shells inside temp workspaces that automated cleanup may delete."],"tags":["go","filesystem","environment","panic","developer-tooling"],"backgroundTag":null,"analyzedSha":"a899afc0eb0b122b323c7ea5ba8e31e3b4ca4b8e","analyzedAt":"2026-08-15T17:03:09.721Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}