golang/go · error

cannot match "all": %v

Error message

cannot match "all": %v

What it means

Raised by query.validate when the 'go get' pattern is the meta-package 'all' but no main module (go.mod) exists in the current working directory. 'all' means 'all packages in the main module and its dependencies', which is meaningless outside module mode. The wrapped value is a modload.NoMainModulesError describing the absence.

Source

Thrown at src/cmd/go/internal/modget/query.go:191

	if err := q.validate(ld); err != nil {
		return q, err
	}
	return q, nil
}

// validate reports a non-nil error if q is not sensible and well-formed.
func (q *query) validate(ld *modload.Loader) error {
	if q.patternIsLocal {
		if q.rawVersion != "" {
			return fmt.Errorf("can't request explicit version %q of path %q in main module", q.rawVersion, q.pattern)
		}
		return nil
	}

	if q.pattern == "all" {
		// If there is no main module, "all" is not meaningful.
		if !ld.HasModRoot() {
			return fmt.Errorf(`cannot match "all": %v`, modload.NewNoMainModulesError(ld))
		}
		if !versionOkForMainModule(q.version) {
			// TODO(bcmills): "all@none" seems like a totally reasonable way to
			// request that we remove all module requirements, leaving only the main
			// module and standard library. Perhaps we should implement that someday.
			return &modload.QueryUpgradesAllError{
				MainModules: ld.MainModules.Versions(),
				Query:       q.version,
			}
		}
	}

	if search.IsMetaPackage(q.pattern) && q.pattern != "all" {
		if q.pattern != q.raw {
			if q.pattern == "tool" {
				return fmt.Errorf("can't request explicit version of \"tool\" pattern")
			}
			return fmt.Errorf("can't request explicit version of standard-library pattern %q", q.pattern)

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Run `go mod init <module-path>` in the project root to create a go.mod, then re-run `go get all`.
  2. Move into a directory that is inside an existing module before running `go get all`.
  3. If you genuinely need pre-module GOPATH behavior, set GO111MODULE=off (legacy, not recommended).

Example fix

// before
$ cd /tmp/scratch && go get all
// after
$ cd /tmp/scratch && go mod init example.com/scratch && go get all
Defensive patterns

Strategy: validation

Validate before calling

// Before invoking `go get all`, ensure a module is present.
import (
    "os"
    "path/filepath"
)

func hasGoMod(start string) bool {
    dir := start
    for {
        if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
            return true
        }
        parent := filepath.Dir(dir)
        if parent == dir {
            return false
        }
        dir = parent
    }
}

// usage:
// if !hasGoMod(".") { run `go mod init <path>` or abort }

Prevention

When it happens

Trigger: Running `go get all` (or any get command resolving pattern 'all') in a directory tree that contains no go.mod file and is not inside one. Reached from modget.query.validate when ld.HasModRoot() returns false.

Common situations: User opens a fresh directory and runs `go get all` before `go mod init`; GOPATH-mode legacy workflow being attempted on a Go version that defaults to modules; running inside /tmp or HOME without a module.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/16e30749a50bf307. Report an issue: GitHub.