{"record":{"id":"88cdff13eff1f7f3","repo":"golang/go","slug":"s-v-88cdff","errorCode":null,"errorMessage":"%s: %v","messagePattern":"%s: %v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/modindex/build.go","lineNumber":280,"sourceCode":"\t// when we create the index file?\n\tvar ignoreBinaryOnly bool\n\tif strings.HasSuffix(name, \".go\") {\n\t\terr = readGoInfo(f, info)\n\t\tif strings.HasSuffix(name, \"_test.go\") {\n\t\t\tignoreBinaryOnly = true // ignore //go:binary-only-package comments in _test.go files\n\t\t}\n\t} else {\n\t\tinfo.header, err = readComments(f)\n\t}\n\tf.Close()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"read %s: %v\", info.name, err)\n\t}\n\n\t// Look for +build comments to accept or reject the file.\n\tinfo.goBuildConstraint, info.plusBuildConstraints, info.binaryOnly, err = getConstraints(info.header)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%s: %v\", name, err)\n\t}\n\n\tif ignoreBinaryOnly && info.binaryOnly {\n\t\tinfo.binaryOnly = false // override info.binaryOnly\n\t}\n\n\treturn info, nil\n}\n\nfunc cleanDecls(m map[string][]token.Position) ([]string, map[string][]token.Position) {\n\tall := make([]string, 0, len(m))\n\tfor path := range m {\n\t\tall = append(all, path)\n\t}\n\tsort.Strings(all)\n\treturn all, m\n}\n","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/modindex/build.go#L262-L298","documentation":"Wrapped error from getConstraints when parsing build-constraint comments (//go:build, // +build, or //go:binary-only-package) out of a file's leading comment header during module-index construction. The %s is the bare file name (no dir) and %v is the underlying constraint-parsing error such as 'multiple //go:build comments' or a malformed constraint expression.","triggerScenarios":"A source file in the module has two or more //go:build lines, an unparseable //go:build expression, or another error surfaced by getConstraints. getFileInfo wraps it as `<name>: <err>`.","commonSituations":"Editing a file and accidentally leaving a duplicate //go:build line after a merge; using old-style '// +build' syntax that violates the parsing rules; copy-pasting a constraint that contains a typo such as `//go:build go1.21.`.","solutions":["Open the named file and locate the //go:build / // +build comment block in its header (must be before the package clause, separated by a blank line).","Ensure there is exactly one //go:build line; remove any duplicates (errMultipleGoBuild).","Validate the expression with `go vet ./...` after fixing; vet reports build-constraint syntax errors.","Move the constraint comments above the `package` declaration with a blank line separating them from code."],"exampleFix":"// before (two constraints)\n//go:build linux\n//go:build amd64\npackage foo\n// after\n//go:build linux && amd64\npackage foo","handlingStrategy":"validation","validationCode":"// Use go/build/constraint to lint every //go:build comment before build.\nimport \"go/build/constraint\"\n\nfunc lintBuildConstraints(header []byte) error {\n    for _, line := range bytes.Split(header, []byte(\"\\n\")) {\n        if bytes.HasPrefix(bytes.TrimSpace(line), []byte(\"//go:build\")) {\n            if _, err := constraint.Parse(string(line)); err != nil {\n                return err\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `go vet ./...` in CI — it flags malformed build constraints.","Keep exactly one //go:build line per file, above the package clause, separated by a blank line.","Add an editor lint rule for duplicate //go:build comments."],"tags":["build-constraints","go-build","parsing","module-index"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}