{"record":{"id":"fb7bb69c4a6cbd13","repo":"golang/go","slug":"invalid-buildmode-q","errorCode":null,"errorMessage":"invalid buildmode: %q","messagePattern":"invalid buildmode: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/link/internal/ld/config.go","lineNumber":34,"sourceCode":"// in cmd/go, and are documented in 'go help buildmode'.\ntype BuildMode uint8\n\nconst (\n\tBuildModeUnset BuildMode = iota\n\tBuildModeExe\n\tBuildModePIE\n\tBuildModeCArchive\n\tBuildModeCShared\n\tBuildModeShared\n\tBuildModePlugin\n)\n\n// Set implements flag.Value to set the build mode based on the argument\n// to the -buildmode flag.\nfunc (mode *BuildMode) Set(s string) error {\n\tswitch s {\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid buildmode: %q\", s)\n\tcase \"exe\":\n\t\tswitch buildcfg.GOOS + \"/\" + buildcfg.GOARCH {\n\t\tcase \"darwin/arm64\", \"windows/arm64\": // On these platforms, everything is PIE\n\t\t\t*mode = BuildModePIE\n\t\tdefault:\n\t\t\t*mode = BuildModeExe\n\t\t}\n\tcase \"pie\":\n\t\t*mode = BuildModePIE\n\tcase \"c-archive\":\n\t\t*mode = BuildModeCArchive\n\tcase \"c-shared\":\n\t\t*mode = BuildModeCShared\n\tcase \"shared\":\n\t\t*mode = BuildModeShared\n\tcase \"plugin\":\n\t\t*mode = BuildModePlugin\n\t}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/link/internal/ld/config.go#L16-L52","documentation":"The Go linker's BuildMode.Set method rejects an unrecognized -buildmode flag value. Valid build modes are: exe (standalone executable), pie (position-independent executable), c-archive (C-compatible static archive), c-shared (C-compatible shared library), shared (shared library for Go programs), and plugin (Go plugin). Any other string triggers this error.","triggerScenarios":"The flag.Value Set method is called by the Go flag parser with the user-supplied -buildmode argument. If the string does not match any of the six known cases, the default branch returns this formatted error including the offending value.","commonSituations":"Typo in the buildmode name (e.g. 'c-share' instead of 'c-shared'); using a deprecated buildmode name; passing a value intended for a different flag; shell quoting issues that concatenate the flag and value incorrectly.","solutions":["Check the valid buildmode values: go help buildmode","Correct the spelling to one of: exe, pie, c-archive, c-shared, shared, plugin","Verify shell quoting is correct: -buildmode=c-shared not -buildmode c -shared","If using a build script, ensure the buildmode variable is set correctly"],"exampleFix":"# before\ngo build -buildmode=library main.go\n\n# after\ngo build -buildmode=c-archive main.go","handlingStrategy":"validation","validationCode":"// Validate buildmode before passing to linker\nvar validBuildModes = map[string]bool{\n    \"exe\": true, \"pie\": true, \"c-archive\": true,\n    \"c-shared\": true, \"shared\": true, \"plugin\": true,\n}\n\nfunc validateBuildMode(s string) error {\n    if !validBuildModes[s] {\n        return fmt.Errorf(\"invalid buildmode %q; valid: exe, pie, c-archive, c-shared, shared, plugin\", s)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Handle buildmode errors in build scripts\nif err := mode.Set(buildmodeFlag); err != nil {\n    fmt.Fprintf(os.Stderr, \"Error: %v\\nRun 'go help buildmode' for valid options.\\n\", err)\n    os.Exit(1)\n}","preventionTips":["Check valid values with: go help buildmode","Validate buildmode in build scripts before invoking go build","Use shell completion or validation in CI to catch typos"],"tags":["buildmode","configuration","linker","go-toolchain","cli-flag"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}