{"record":{"id":"a28c7922daed1149","repo":"hashicorp/nomad","slug":"could-not-find-nomad-executable-v-v","errorCode":null,"errorMessage":"Could not find Nomad executable (%v): %v","messagePattern":"Could not find Nomad executable \\((.+?)\\): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/discover/discover.go","lineNumber":47,"sourceCode":"\tif _, err := os.Stat(bin); err == nil && isNomad(bin, nomadExe) {\n\t\treturn bin, nil\n\t}\n\n\t// Check the $PATH\n\tif bin, err := exec.LookPath(nomadExe); err == nil {\n\t\treturn bin, nil\n\t}\n\n\t// Check the $GOPATH.\n\tbin = filepath.Join(os.Getenv(\"GOPATH\"), \"bin\", nomadExe)\n\tif _, err := os.Stat(bin); err == nil {\n\t\treturn bin, nil\n\t}\n\n\t// Check the CWD.\n\tpwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"Could not find Nomad executable (%v): %v\", nomadExe, err)\n\t}\n\n\tbin = filepath.Join(pwd, nomadExe)\n\tif _, err := os.Stat(bin); err == nil {\n\t\treturn bin, nil\n\t}\n\n\t// Check CWD/bin\n\tbin = filepath.Join(pwd, \"bin\", nomadExe)\n\tif _, err := os.Stat(bin); err == nil {\n\t\treturn bin, nil\n\t}\n\n\treturn \"\", fmt.Errorf(\"Could not find Nomad executable (%v)\", nomadExe)\n}\n\nfunc isNomad(path, nomadExe string) bool {\n\tif strings.HasSuffix(path, \".test\") || strings.HasSuffix(path, \".test.exe\") {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/discover/discover.go#L29-L65","documentation":"NomadExecutable() searches the current working directory for the nomad binary. This error wraps os.Getwd() failure, meaning the process's working directory cannot be determined (often because the cwd directory was deleted), so the CWD lookup stage cannot proceed.","triggerScenarios":"Calling NomadExecutable() when os.Getwd() fails — typically the current working directory has been removed or renamed while the process runs, or permission was lost on a cwd path component.","commonSituations":"Test runner started in a temp directory that a cleanup process deleted; working on a mounted/removed volume; cwd on an NFS mount that dropped; CI job whose workspace was pruned mid-run.","solutions":["Run the test binary from an existing, stable directory (cd to a valid path before launching).","Recreate the deleted working directory and rerun the tests.","In CI, ensure the workspace directory is not pruned while tests execute.","Prefer invoking tests with an absolute path from an always-present directory (e.g. the repo root)."],"exampleFix":"// before\ncd $(mktemp -d) && rm -rf \"$PWD\" & ./nomad.test // Getwd fails\n// after\ncd /path/to/repo && ./nomad.test # stable cwd","handlingStrategy":"try-catch","validationCode":"// Verify a usable cwd before invoking the helper\nif wd, err := os.Getwd(); err != nil {\n\tlog.Warn(\"working directory is unusable; restarting from repo root\")\n\terr = os.Chdir(repoRoot)\n} else if _, err := os.Stat(wd); err != nil {\n\terr = os.Chdir(repoRoot)\n}","typeGuard":"func isGetwdError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"Could not find Nomad executable\")\n}","tryCatchPattern":"bin, err := discover.NomadExecutable()\nif err != nil {\n\tif isGetwdError(err) {\n\t\t// cwd deleted: chdir to a valid dir and retry\n\t\tif chErr := os.Chdir(repoRoot); chErr == nil {\n\t\t\tbin, err = discover.NomadExecutable()\n\t\t}\n\t}\n\treturn err\n}","preventionTips":["Launch tests from a directory that persists for the whole run","Avoid mktemp cwd + rm -rf patterns around test execution","Keep CI workspaces alive until the test process exits","Watch for unmounted NFS/volumes as cwd"],"tags":["discovery","working-directory","testing","filesystem"],"backgroundTag":"working-directory-unavailable","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}