{"record":{"id":"32c49191e5fd560f","repo":"golang/go","slug":"invalid-headtype-q","errorCode":null,"errorMessage":"invalid headtype: %q","messagePattern":"invalid headtype: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/objabi/head.go","lineNumber":81,"sourceCode":"\t\t*h = Hfreebsd\n\tcase \"js\":\n\t\t*h = Hjs\n\tcase \"linux\", \"android\":\n\t\t*h = Hlinux\n\tcase \"netbsd\":\n\t\t*h = Hnetbsd\n\tcase \"openbsd\":\n\t\t*h = Hopenbsd\n\tcase \"plan9\":\n\t\t*h = Hplan9\n\tcase \"illumos\", \"solaris\":\n\t\t*h = Hsolaris\n\tcase \"wasip1\":\n\t\t*h = Hwasip1\n\tcase \"windows\":\n\t\t*h = Hwindows\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid headtype: %q\", s)\n\t}\n\treturn nil\n}\n\nfunc (h HeadType) String() string {\n\tswitch h {\n\tcase Haix:\n\t\treturn \"aix\"\n\tcase Hdarwin:\n\t\treturn \"darwin\"\n\tcase Hdragonfly:\n\t\treturn \"dragonfly\"\n\tcase Hfreebsd:\n\t\treturn \"freebsd\"\n\tcase Hjs:\n\t\treturn \"js\"\n\tcase Hlinux:\n\t\treturn \"linux\"","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/objabi/head.go#L63-L99","documentation":"HeadType is an enum representing the output binary format (ELF, Mach-O, PE, etc.), selected based on the target GOOS. `HeadType.Set` maps OS name strings to their corresponding head type. When the provided string does not match any known OS, the error is returned. This is typically set internally by the linker from GOOS, but can be overridden via flags.","triggerScenarios":"Setting `-H` or `--headtype` (or equivalent) to a string that is not in the recognized list: aix, darwin, dragonfly, freebsd, linux, netbsd, openbsd, plan9, illumos, solaris, wasip1, windows. Also triggered when an internal code path passes an unsupported GOOS string.","commonSituations":"Using a custom build wrapper that injects a `-H` value. Building for an experimental or unsupported target. Typo in the headtype name. Using a Go version that does not yet support a particular target OS.","solutions":["Verify the headtype string matches a supported GOOS exactly (case-sensitive: lowercase).","Check `go tool dist list` to confirm the target OS is supported by your Go version.","Remove any custom `-H` flag and let the toolchain infer the head type from GOOS/GOARCH."],"exampleFix":"// before\n$ go tool link -H gnulinux main.o\n\n// after\n$ go tool link -H linux main.o\n// or omit the flag entirely:\n$ go build main.go","handlingStrategy":"validation","validationCode":"// Validate GOOS string before setting headtype\nvar validHeadTypes = map[string]bool{\n    \"aix\": true, \"darwin\": true, \"dragonfly\": true, \"freebsd\": true,\n    \"linux\": true, \"netbsd\": true, \"openbsd\": true, \"plan9\": true,\n    \"illumos\": true, \"solaris\": true, \"wasip1\": true, \"windows\": true,\n}\nfunc isValidHeadType(s string) bool {\n    return validHeadTypes[s]\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use 'go tool dist list' to see supported GOOS values.","Let the toolchain infer the head type from GOOS — do not set -H manually.","Cross-check any custom -H value against the source switch cases in head.go."],"tags":["headtype","linker","binary-format","goos"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}