{"record":{"id":"1935edaf0e8c048f","repo":"golang/go","slug":"missing-command","errorCode":null,"errorMessage":"missing command","messagePattern":"missing command","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/internal/script/engine.go","lineNumber":452,"sourceCode":"\t\t\t\ti++ // skip over second ' before next iteration\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// ending a quoted chunk\n\t\t\trawArg = append(rawArg, argFragment{s: line[start:i], quoted: true})\n\t\t\tstart = i + 1\n\t\t\tquoted = false\n\t\t\tcontinue\n\t\t}\n\t\t// found character worth saving; make sure we're saving\n\t\tif start < 0 {\n\t\t\tstart = i\n\t\t}\n\t}\n\n\tif cmd.name == \"\" {\n\t\tif cmd.want != \"\" || len(cmd.conds) > 0 || len(cmd.rawArgs) > 0 || cmd.background {\n\t\t\t// The line contains a command prefix or suffix, but no actual command.\n\t\t\treturn nil, errors.New(\"missing command\")\n\t\t}\n\n\t\t// The line is blank, or contains only a comment.\n\t\treturn nil, nil\n\t}\n\n\tif n := len(cmd.rawArgs); n > 0 {\n\t\tlast := cmd.rawArgs[n-1]\n\t\tif len(last) == 1 && !last[0].quoted && last[0].s == \"&\" {\n\t\t\tcmd.background = true\n\t\t\tcmd.rawArgs = cmd.rawArgs[:n-1]\n\t\t}\n\t}\n\treturn cmd, nil\n}\n\n// expandArgs expands the shell variables in rawArgs and joins them to form the\n// final arguments to pass to a command.","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/internal/script/engine.go#L434-L470","documentation":"Thrown at the end of parse() when the line produced prefixes, conditions, arguments, or a background marker but no command name (cmd.name == \"\"). A line that is entirely blank or a comment returns (nil, nil); a line that has modifiers but no actual command is a syntax error. The guard checks cmd.want, cmd.conds, cmd.rawArgs, and cmd.background.","triggerScenarios":"A script line like `! ` (negation prefix but no command), `[cond]` alone, `? ` with nothing after, or a trailing `&` background marker on an otherwise empty line, or arguments supplied without a command name.","commonSituations":"Script-test author writes a prefix expecting to continue on the same line and forgets the command, or deletes the command while leaving a condition/prefix during editing.","solutions":["Add the command after the prefix/condition: `! nonexistent-cmd` not `! `.","Remove orphan prefixes/conditions/arguments if no command is intended (a truly blank line is fine).","Re-check that the command name was not accidentally quoted into a different token position."],"exampleFix":"// before\n! \n# -> missing command\n\n// after\n! nonexistent-binary arg","handlingStrategy":"validation","validationCode":"// A line must have a command name if it carries any prefix/cond/arg/&.\nfunc hasCommand(line string) bool {\n    t := strings.TrimSpace(line)\n    // strip leading ! ? and [cond] tokens\n    for strings.HasPrefix(t, \"!\") || strings.HasPrefix(t, \"?\") || (strings.HasPrefix(t, \"[\") && strings.Contains(t, \"]\")) {\n        if strings.HasPrefix(t, \"[\") {\n            t = strings.TrimSpace(t[strings.Index(t, \"]\")+1:])\n        } else {\n            t = strings.TrimSpace(t[1:])\n        }\n    }\n    return t != \"\" && t != \"&\"\n}","typeGuard":"func isMissingCommand(err error) bool {\n    return err != nil && err.Error() == \"missing command\"\n}","tryCatchPattern":"// Lint script lines so any prefix/condition/& is followed by a real command.","preventionTips":["Always follow a prefix or condition with an actual command.","Delete orphan prefixes/conditions rather than leaving them.","Lint for lines ending in '&' with no command."],"tags":["script","parser","test-framework","syntax-error"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}