kubernetes/kubernetes · error

failed to run %q: %s (%s)

Error message

failed to run %q: %s (%s)

What it means

Returned by runCommandInDir in cmd/dependencyverifier/dependencyverifier.go:70 when exec.Command(...).CombinedOutput() returns a non-nil error. It wraps the joined command string, the Go exec error, and the combined output. dependencyverifier runs 'go mod graph' and 'go list -m ...' to detect unwanted/pinned dependency violations, so failures usually stem from the Go toolchain, module cache, or vendoring state.

Source

Thrown at cmd/dependencyverifier/dependencyverifier.go:70

	// references to modules in the spec.unwantedModules list, based on `go mod graph` content.
	// eliminating things from this list is good, and sometimes requires working with upstreams to do so.
	UnwantedReferences map[string][]string `json:"unwantedReferences"`
	// list of modules in the spec.unwantedModules list which are vendored
	UnwantedVendored []string `json:"unwantedVendored"`
}

// runCommand runs the cmd and returns the combined stdout and stderr, or an
// error if the command failed.
func runCommand(cmd ...string) (string, error) {
	return runCommandInDir("", cmd)
}

func runCommandInDir(dir string, cmd []string) (string, error) {
	c := exec.Command(cmd[0], cmd[1:]...)
	c.Dir = dir
	output, err := c.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("failed to run %q: %s (%s)", strings.Join(cmd, " "), err, output)
	}
	return string(output), nil
}

func readFile(path string) (string, error) {
	content, err := os.ReadFile(path)
	// Convert []byte to string and print to screen
	return string(content), err
}

func moduleInSlice(a module, list []module, matchVersion bool) bool {
	for _, b := range list {
		if b == a {
			return true
		}
		if !matchVersion && b.name == a.name {
			return true
		}

View on GitHub (pinned to b882c60b40)

Solutions

  1. Confirm `go` is on PATH and `go mod graph` succeeds in the repo root
  2. Read the (%s) combined-output in the error for the underlying Go message
  3. Run `go env` to verify GOPATH/GOMODCACHE, then `go mod download` to refresh
  4. Ensure vendor/modules.txt is present and in sync (the tool reads it after the graph step)

Example fix

# before: go missing in CI
- run: ./dependencyverifier dependencies.json
# -> failed to run "go mod graph": exec: "go": executable file not found in $PATH ()

# after: install Go first
- uses: actions/setup-go@v5
  with:
    go-version-file: go.mod
- run: ./dependencyverifier dependencies.json
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: ensure `go` is available and the module graph builds before running the verifier.
func preflight() error {
    if _, err := exec.LookPath("go"); err != nil {
        return errors.New("go toolchain not on PATH; install Go before running dependencyverifier")
    }
    if _, err := os.Stat("vendor/modules.txt"); err != nil {
        return errors.New("vendor/modules.txt missing; run hack/update-vendor.sh first")
    }
    return nil
}

Try / catch

// Run the verifier and surface the wrapped command/output to CI logs.
out, err := runCommandInDir("", []string{"go", "mod", "graph"})
if err != nil {
    // err already includes joined command + Go exec error + combined output
    return fmt.Errorf("dependencyverifier preflight failed; inspect output: %w", err)
}

Prevention

When it happens

Trigger: `go` not on PATH; run outside a Go module directory; `go mod graph` fails on a malformed go.mod; `go list` fails due to missing replace directives or broken go.work; vendor/modules.txt absent (read later) or out of sync.

Common situations: CI image missing Go; corrupt GOMODCACHE; go.work referencing deleted staging modules; running the verifier from the wrong working directory.

Related errors


AI-assisted analysis of kubernetes/kubernetes@b882c60b40 (2026-08-07). Data as JSON: /api/errors/a2cc972e2c8a6372. Report an issue: GitHub.