{"record":{"id":"5900a7cb3a7a4100","repo":"golang/go","slug":"invalid-flag-in-s-s-without-argument-see-https","errorCode":null,"errorMessage":"invalid flag in %s: %s without argument (see https://go.dev/s/invalidflag)","messagePattern":"invalid flag in (.+?): (.+?) without argument \\(see https://go\\.dev/s/invalidflag\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/work/security.go","lineNumber":462,"sourceCode":"\t\t\t\t\tload.SafeArg(list[i+1][4:]) &&\n\t\t\t\t\t!strings.Contains(list[i+1][4:], \",\") {\n\t\t\t\t\ti++\n\t\t\t\t\tcontinue Args\n\t\t\t\t}\n\n\t\t\t\t// Permit -I= /path, -I $SYSROOT.\n\t\t\t\tif i+1 < len(list) && arg == \"-I\" {\n\t\t\t\t\tif (strings.HasPrefix(list[i+1], \"=\") || strings.HasPrefix(list[i+1], \"$SYSROOT\")) &&\n\t\t\t\t\t\tload.SafeArg(list[i+1][1:]) {\n\t\t\t\t\t\ti++\n\t\t\t\t\t\tcontinue Args\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif i+1 < len(list) {\n\t\t\t\t\treturn fmt.Errorf(\"invalid flag in %s: %s %s (see https://go.dev/s/invalidflag)\", source, arg, list[i+1])\n\t\t\t\t}\n\t\t\t\treturn fmt.Errorf(\"invalid flag in %s: %s without argument (see https://go.dev/s/invalidflag)\", source, arg)\n\t\t\t}\n\t\t}\n\tBad:\n\t\treturn fmt.Errorf(\"invalid flag in %s: %s (see https://go.dev/s/invalidflag)\", source, arg)\n\t}\n\treturn nil\n}\n","sourceCodeStart":444,"sourceCodeEnd":470,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/work/security.go#L444-L470","documentation":"Thrown by checkFlags when a flag that expects an argument (e.g. `-I`) appears as the last token in the list with no value following it. The error reports the flag and notes it is missing its argument.","triggerScenarios":"A #cgo CFLAGS line or CGO_CFLAGS list ends with a bare `-I` (or similar argument-taking flag): i+1 is out of range, so checkFlags returns the `without argument` form.","commonSituations":"Truncation while editing a #cgo line; a generated/templated flag list that dropped the trailing path; mis-ordered flags where the intended value landed on the next line.","solutions":["Append the missing argument after the flag (e.g. `-I ./include`).","Remove the dangling flag if the path is not needed.","Re-run `go build` after the fix to confirm the error clears.","Lint #cgo directives in vendored C packages before upgrading."],"exampleFix":"// before\n// #cgo CFLAGS: -O2 -I\n\n// after\n// #cgo CFLAGS: -O2 -I ./include","handlingStrategy":"validation","validationCode":"// Ensure argument-taking flags are not dangling\nflags := strings.Fields(os.Getenv(\"CGO_CFLAGS\"))\nargTaking := map[string]bool{\"-I\": true, \"-L\": true, \"-D\": true, \"-U\": true, \"-include\": true}\nif argTaking[flags[len(flags)-1]] {\n    log.Fatalf(\"%s has no argument\", flags[len(flags)-1])\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never end a #cgo CFLAGS line with a bare -I/-L/-D.","Lint generated cgo flag lists.","Re-read edited #cgo directives before commit."],"tags":["go-toolchain","cgo","flags","validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}