{"record":{"id":"16e30749a50bf307","repo":"golang/go","slug":"cannot-match-all-v","errorCode":null,"errorMessage":"cannot match \"all\": %v","messagePattern":"cannot match \"all\": (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modget/query.go","lineNumber":191,"sourceCode":"\tif err := q.validate(ld); err != nil {\n\t\treturn q, err\n\t}\n\treturn q, nil\n}\n\n// validate reports a non-nil error if q is not sensible and well-formed.\nfunc (q *query) validate(ld *modload.Loader) error {\n\tif q.patternIsLocal {\n\t\tif q.rawVersion != \"\" {\n\t\t\treturn fmt.Errorf(\"can't request explicit version %q of path %q in main module\", q.rawVersion, q.pattern)\n\t\t}\n\t\treturn nil\n\t}\n\n\tif q.pattern == \"all\" {\n\t\t// If there is no main module, \"all\" is not meaningful.\n\t\tif !ld.HasModRoot() {\n\t\t\treturn fmt.Errorf(`cannot match \"all\": %v`, modload.NewNoMainModulesError(ld))\n\t\t}\n\t\tif !versionOkForMainModule(q.version) {\n\t\t\t// TODO(bcmills): \"all@none\" seems like a totally reasonable way to\n\t\t\t// request that we remove all module requirements, leaving only the main\n\t\t\t// module and standard library. Perhaps we should implement that someday.\n\t\t\treturn &modload.QueryUpgradesAllError{\n\t\t\t\tMainModules: ld.MainModules.Versions(),\n\t\t\t\tQuery:       q.version,\n\t\t\t}\n\t\t}\n\t}\n\n\tif search.IsMetaPackage(q.pattern) && q.pattern != \"all\" {\n\t\tif q.pattern != q.raw {\n\t\t\tif q.pattern == \"tool\" {\n\t\t\t\treturn fmt.Errorf(\"can't request explicit version of \\\"tool\\\" pattern\")\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"can't request explicit version of standard-library pattern %q\", q.pattern)","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modget/query.go#L173-L209","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run `go mod init <module-path>` in the project root to create a go.mod, then re-run `go get all`.","Move into a directory that is inside an existing module before running `go get all`.","If you genuinely need pre-module GOPATH behavior, set GO111MODULE=off (legacy, not recommended)."],"exampleFix":"// before\n$ cd /tmp/scratch && go get all\n// after\n$ cd /tmp/scratch && go mod init example.com/scratch && go get all","handlingStrategy":"validation","validationCode":"// Before invoking `go get all`, ensure a module is present.\nimport (\n    \"os\"\n    \"path/filepath\"\n)\n\nfunc hasGoMod(start string) bool {\n    dir := start\n    for {\n        if _, err := os.Stat(filepath.Join(dir, \"go.mod\")); err == nil {\n            return true\n        }\n        parent := filepath.Dir(dir)\n        if parent == dir {\n            return false\n        }\n        dir = parent\n    }\n}\n\n// usage:\n// if !hasGoMod(\".\") { run `go mod init <path>` or abort }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `go mod init` as the first step of scaffolding a new project.","Document the required module path in README so CI does not run `go get` outside a module.","In scripts, `test -f go.mod` before any `go get` invocation."],"tags":["go-modules","go-get","go-mod","configuration"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}