{"record":{"id":"6a9c6b4435e58e90","repo":"golang/go","slug":"valid-modes-are-set-count-or-atomic","errorCode":null,"errorMessage":"valid modes are \"set\", \"count\", or \"atomic\"","messagePattern":"valid modes are \"set\", \"count\", or \"atomic\"","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/build.go","lineNumber":946,"sourceCode":"func (f coverFlag) Set(value string) error {\n\tif err := f.V.Set(value); err != nil {\n\t\treturn err\n\t}\n\tcfg.BuildCover = true\n\treturn nil\n}\n\ntype coverModeFlag string\n\nfunc (f coverModeFlag) String() string { return string(f) }\nfunc (f *coverModeFlag) Set(value string) error {\n\tswitch value {\n\tcase \"\", \"set\", \"count\", \"atomic\":\n\t\t*f = coverModeFlag(value)\n\t\tcfg.BuildCoverMode = value\n\t\treturn nil\n\tdefault:\n\t\treturn errors.New(`valid modes are \"set\", \"count\", or \"atomic\"`)\n\t}\n}\n\n// A commaListFlag is a flag.Value representing a comma-separated list.\ntype commaListFlag struct{ Vals *[]string }\n\nfunc (f commaListFlag) String() string { return strings.Join(*f.Vals, \",\") }\n\nfunc (f commaListFlag) Set(value string) error {\n\tif value == \"\" {\n\t\t*f.Vals = nil\n\t} else {\n\t\t*f.Vals = strings.Split(value, \",\")\n\t}\n\treturn nil\n}\n\n// A stringFlag is a flag.Value representing a single string.","sourceCodeStart":928,"sourceCodeEnd":964,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/build.go#L928-L964","documentation":"Thrown by coverModeFlag.Set in cmd/go/internal/work when -covermode is given a value other than \"set\", \"count\", \"atomic\", or empty. -covermode controls how coverage is recorded per basic block: set (boolean), count (integer), atomic (integer with sync for racing tests). Any other spelling is rejected.","triggerScenarios":"Running `go test -covermode=branch`, `-covermode=line`, `-covermode=on/off`, or a typo like `-covermode=atmoic`. CI configs that pass an unsupported mode name. Documentation that conflates -covermode with -coverpkg.","commonSituations":"Developers familiar with gcov/lcov mode names expecting \"branch\" or \"line\". Auto-generated coverage matrices that interpolate a variable into -covermode. Typos.","solutions":["Use one of: set, count, atomic (or omit the flag; go picks a sensible default based on -race).","If you need branch/condition coverage, that is not supported by the Go coverage tool — use a separate tool or the new GOCOVERDIR-based coverage collection.","Validate the value against {\"set\",\"count\",\"atomic\"} in your CI script before invoking go test.","Check for shell aliases or Makefile variables that mangle the flag value."],"exampleFix":"# before\ngo test -covermode=branch ./...\n# after\ngo test -covermode=count ./...","handlingStrategy":"validation","validationCode":"var validCoverModes = map[string]bool{\"set\": true, \"count\": true, \"atomic\": true}\nif mode != \"\" && !validCoverModes[mode] {\n    return fmt.Errorf(\"-covermode %q invalid; want set|count|atomic\", mode)\n}","typeGuard":"func isValidCoverMode(s string) bool {\n    return s == \"\" || s == \"set\" || s == \"count\" || s == \"atomic\"\n}","tryCatchPattern":null,"preventionTips":["Restrict -covermode values in CI templates to the three supported strings.","Remember branch/line coverage is not supported by the standard tool.","Prefer the default (omit the flag) unless you need count/atomic semantics."],"tags":["go-toolchain","coverage","flag","test","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}