{"record":{"id":"4f393a6f959824df","repo":"kubernetes/minikube","slug":"run-extract-go-from-the-minikube-root-directory","errorCode":null,"errorMessage":"run extract.go from the minikube root directory","messagePattern":"run extract\\.go from the minikube root directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/extract/extract.go","lineNumber":43,"sourceCode":"\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":25,"sourceCodeEnd":55,"githubUrl":"https://github.com/kubernetes/minikube/blob/a899afc0eb0b122b323c7ea5ba8e31e3b4ca4b8e/cmd/extract/extract.go#L25-L55","documentation":"The extract tool requires being launched from the minikube repository root because it scans hardcoded relative paths (\"cmd\", \"pkg\") and writes to translations/. This panic is a deliberate guard: it calls os.Getwd() and panics if the returned path contains the substring \"cmd\", which happens when the tool is run from inside cmd/extract rather than from the repo root. Note the check is substring-based, so any parent directory containing \"cmd\" (e.g. a checkout at /home/user/cmd/minikube or C:\\cmd\\minikube) also trips it even from the root.","triggerScenarios":"Running the tool with the shell's cwd inside cmd/ or cmd/extract (e.g. `cd cmd/extract && go run extract.go`); or, as a false positive, running from a correctly rooted checkout whose absolute path merely contains \"cmd\" as a substring of some parent directory.","commonSituations":"A developer cds into the file's directory in their editor's integrated terminal and runs go run there; a machine whose workspace lives under a path like /srv/cmd-work/minikube or D:\\cmd\\minikube on Windows, which trips the substring check even though the cwd is the repo root.","solutions":["Change to the minikube repository root and run `go run cmd/extract/extract.go` (or `go run ./cmd/extract`) from there.","If you are already at the root but still hit the panic, your checkout path contains \"cmd\" somewhere; move/rename the checkout (e.g. /home/user/src/minikube) so the substring check no longer matches.","As a maintainer improvement, replace the substring test with an exact check such as filepath.Base(cwd) == \"minikube\" or os.Stat(\"pkg/minikube/reason/known_issues.go\")."],"exampleFix":"// before\nif strings.Contains(cwd, \"cmd\") {\n    panic(\"run extract.go from the minikube root directory\")\n}\n\n// after\nif filepath.Base(cwd) != \"minikube\" {\n    panic(\"run extract.go from the minikube root directory\")\n}","handlingStrategy":"validation","validationCode":"// Run before executing the tool: verify you are at the repo root.\ncwd, _ := os.Getwd()\nif filepath.Base(cwd) != \"minikube\" {\n    log.Fatal(\"run extract.go from the minikube root directory\")\n}\n// Shell equivalent before `go run cmd/extract/extract.go`:\n// [ \"$(basename \"$PWD\")\" = minikube ] || { echo \"cd to minikube root first\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always launch the tool from the repository root: `go run ./cmd/extract`, never from inside cmd/extract.","Keep checkouts out of paths containing \"cmd\" as a substring, since the current guard matches any parent (e.g. avoid /home/user/cmd/minikube).","Prefer an exact root check (filepath.Base(cwd), or stat of a root-only marker file) over substring matching when patching the guard.","Document the launch requirement in the tool's package comment so contributors do not discover it via panic."],"tags":["go","working-directory","panic","developer-tooling","path-handling"],"backgroundTag":null,"analyzedSha":"a899afc0eb0b122b323c7ea5ba8e31e3b4ca4b8e","analyzedAt":"2026-08-15T17:03:09.721Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}