hashicorp/nomad · error

failed to find nomad binary: %v

Error message

failed to find nomad binary: %v

What it means

When the running process is a Go test binary (name ends with .test), Self() substitutes the real 'nomad' binary found via exec.LookPath so tests can spawn real subprocesses. If 'nomad' is not on PATH, the process panics. This only affects test environments.

Source

Thrown at helper/subproc/self.go:32

var (
	// executable is the executable of this process
	executable string
	once       sync.Once
)

// Self returns the path to the executable of this process.
func Self() string {
	once.Do(func() {
		s, err := os.Executable()
		if err != nil {
			panic(fmt.Sprintf("failed to detect executable: %v", err))
		}

		// when running tests, we need to use the real nomad binary,
		// and make sure you recompile between changes!
		if strings.HasSuffix(s, ".test") {
			if s, err = exec.LookPath("nomad"); err != nil {
				panic(fmt.Sprintf("failed to find nomad binary: %v", err))
			}
		}
		executable = s
	})
	return executable
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Build the nomad binary ('go build -o nomad .') and add it to PATH before running tests (source comments: recompile between changes)
  2. Run tests via the repo's Makefile 'make test' target, which handles building nomad first
  3. Verify PATH inside the test environment includes the directory containing the nomad binary

Example fix

// before
go test ./helper/subproc/...
// after
go build -o ./bin/nomad . && PATH="$(pwd)/bin:$PATH" go test ./helper/subproc/...
Defensive patterns

Strategy: validation

Validate before calling

if _, err := exec.LookPath("nomad"); err != nil { t.Skipf("nomad binary not on PATH: %v", err) }

Try / catch

defer func() { if r := recover(); r != nil { if s, ok := r.(string); ok && strings.Contains(s, "failed to find nomad binary") { t.Fatalf("build nomad and add to PATH: %v", s) }; panic(r) } }()

Prevention

When it happens

Trigger: Running Nomad's Go test suite (or any test linking helper/subproc) where the compiled test binary has a .test suffix and no 'nomad' binary is discoverable via the PATH environment variable.

Common situations: Running 'go test ./...' without having built/installed the nomad binary, having a stale or deleted nomad binary on PATH, or running tests with a stripped PATH (CI containers).

Related errors


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