hashicorp/nomad · error

Could not find Nomad executable (%v): %v

Error message

Could not find Nomad executable (%v): %v

What it means

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.

Source

Thrown at helper/discover/discover.go:47

	if _, err := os.Stat(bin); err == nil && isNomad(bin, nomadExe) {
		return bin, nil
	}

	// Check the $PATH
	if bin, err := exec.LookPath(nomadExe); err == nil {
		return bin, nil
	}

	// Check the $GOPATH.
	bin = filepath.Join(os.Getenv("GOPATH"), "bin", nomadExe)
	if _, err := os.Stat(bin); err == nil {
		return bin, nil
	}

	// Check the CWD.
	pwd, err := os.Getwd()
	if err != nil {
		return "", fmt.Errorf("Could not find Nomad executable (%v): %v", nomadExe, err)
	}

	bin = filepath.Join(pwd, nomadExe)
	if _, err := os.Stat(bin); err == nil {
		return bin, nil
	}

	// Check CWD/bin
	bin = filepath.Join(pwd, "bin", nomadExe)
	if _, err := os.Stat(bin); err == nil {
		return bin, nil
	}

	return "", fmt.Errorf("Could not find Nomad executable (%v)", nomadExe)
}

func isNomad(path, nomadExe string) bool {
	if strings.HasSuffix(path, ".test") || strings.HasSuffix(path, ".test.exe") {

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Run the test binary from an existing, stable directory (cd to a valid path before launching).
  2. Recreate the deleted working directory and rerun the tests.
  3. In CI, ensure the workspace directory is not pruned while tests execute.
  4. Prefer invoking tests with an absolute path from an always-present directory (e.g. the repo root).

Example fix

// before
cd $(mktemp -d) && rm -rf "$PWD" & ./nomad.test // Getwd fails
// after
cd /path/to/repo && ./nomad.test # stable cwd
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify a usable cwd before invoking the helper
if wd, err := os.Getwd(); err != nil {
	log.Warn("working directory is unusable; restarting from repo root")
	err = os.Chdir(repoRoot)
} else if _, err := os.Stat(wd); err != nil {
	err = os.Chdir(repoRoot)
}

Type guard

func isGetwdError(err error) bool {
	return err != nil && strings.Contains(err.Error(), "Could not find Nomad executable")
}

Try / catch

bin, err := discover.NomadExecutable()
if err != nil {
	if isGetwdError(err) {
		// cwd deleted: chdir to a valid dir and retry
		if chErr := os.Chdir(repoRoot); chErr == nil {
			bin, err = discover.NomadExecutable()
		}
	}
	return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/a28c7922daed1149. Report an issue: GitHub.