{"record":{"id":"7abacd1933abb2bd","repo":"golang/go","slug":"s-parsing-go-build-line-v","errorCode":null,"errorMessage":"%s: parsing //go:build line: %v","messagePattern":"(.+?): parsing //go:build line: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/read.go","lineNumber":510,"sourceCode":"\t\t// Check errors for go files and call badGoFiles to put them in\n\t\t// InvalidGoFiles if they do have an error.\n\t\tif strings.HasSuffix(name, \".go\") {\n\t\t\tif error := tf.error(); error != \"\" {\n\t\t\t\tbadGoFile(name, errors.New(tf.error()))\n\t\t\t\tcontinue\n\t\t\t} else if parseError := tf.parseError(); parseError != \"\" {\n\t\t\t\tbadGoFile(name, parseErrorFromString(tf.parseError()))\n\t\t\t\t// Fall through: we still want to list files with parse errors.\n\t\t\t}\n\t\t}\n\n\t\tvar shouldBuild = true\n\t\tif !ctxt.goodOSArchFile(name, allTags) && !ctxt.UseAllFiles {\n\t\t\tshouldBuild = false\n\t\t} else if goBuildConstraint := tf.goBuildConstraint(); goBuildConstraint != \"\" {\n\t\t\tx, err := constraint.Parse(goBuildConstraint)\n\t\t\tif err != nil {\n\t\t\t\treturn p, fmt.Errorf(\"%s: parsing //go:build line: %v\", name, err)\n\t\t\t}\n\t\t\tshouldBuild = ctxt.eval(x, allTags)\n\t\t} else if plusBuildConstraints := tf.plusBuildConstraints(); len(plusBuildConstraints) > 0 {\n\t\t\tfor _, text := range plusBuildConstraints {\n\t\t\t\tif x, err := constraint.Parse(text); err == nil {\n\t\t\t\t\tif !ctxt.eval(x, allTags) {\n\t\t\t\t\t\tshouldBuild = false\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\text := nameExt(name)\n\t\tif !shouldBuild || tf.ignoreFile() {\n\t\t\tif ext == \".go\" {\n\t\t\t\tp.IgnoredGoFiles = append(p.IgnoredGoFiles, name)\n\t\t\t} else if fileListForExt(p, ext) != nil {\n\t\t\t\tp.IgnoredOtherFiles = append(p.IgnoredOtherFiles, name)","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/read.go#L492-L528","documentation":"Returned by IndexPackage.Import when constraint.Parse fails on a file's //go:build constraint line during indexed import. The %s is the bare source file name and %v is the parse error. This is the indexed-import analogue of the live go/build error for malformed build tags.","triggerScenarios":"A .go file in the package contains a //go:build line whose expression is syntactically invalid (unbalanced parens, unknown operators, trailing tokens). constraint.Parse returns an error that Import wraps.","commonSituations":"Editing build tags and introducing a syntax error; merging branches and leaving conflicting tags; using a future Go syntax not supported by the current toolchain.","solutions":["Open the named file and inspect the //go:build line; balance parentheses and use only the supported operators (&&, ||, !).","Run `go vet ./...` to get the precise parse error from the live toolchain.","Validate the constraint against go/build/constraint in isolation if unsure of the grammar."],"exampleFix":"// before\n//go:build linux && (amd64 || arm64\n// after\n//go:build linux && (amd64 || arm64)","handlingStrategy":"validation","validationCode":"// Pre-parse every //go:build line in the package's files.\nimport \"go/build/constraint\"\n\nfunc lintPackageBuildConstraints(pkgDir string) error {\n    entries, _ := os.ReadDir(pkgDir)\n    for _, e := range entries {\n        if !strings.HasSuffix(e.Name(), \".go\") { continue }\n        f, _ := os.Open(filepath.Join(pkgDir, e.Name()))\n        hdr, _, _ := readHeaderComments(f) // your util\n        f.Close()\n        for _, line := range bytes.Split(hdr, []byte(\"\\n\")) {\n            if bytes.HasPrefix(bytes.TrimSpace(line), []byte(\"//go:build\")) {\n                if _, err := constraint.Parse(string(line)); err != nil {\n                    return fmt.Errorf(\"%s: %w\", e.Name(), err)\n                }\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `go vet ./...` in pre-commit and CI.","Use editor tooling (gopls) that reports build-constraint errors live."],"tags":["build-constraints","go-build","parsing","module-index"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}