golang/go · warning

empty command

Error message

empty command

What it means

Thrown by the script parser when the token that would become the command name is an empty unquoted string. After handling prefixes (!/?) and brackets, flushArg guards `arg == ""` for the command-name position. An empty unquoted command name is not meaningful, so it is rejected as a syntax error.

Source

Thrown at src/cmd/internal/script/engine.go:392

			}

			// Command prefix [cond] means only run this command if cond is satisfied.
			if strings.HasPrefix(arg, "[") && strings.HasSuffix(arg, "]") {
				want := true
				arg = strings.TrimSpace(arg[1 : len(arg)-1])
				if strings.HasPrefix(arg, "!") {
					want = false
					arg = strings.TrimSpace(arg[1:])
				}
				if arg == "" {
					return errors.New("empty condition")
				}
				cmd.conds = append(cmd.conds, condition{want: want, tag: arg})
				return nil
			}

			if arg == "" {
				return errors.New("empty command")
			}
			cmd.name = arg
			return nil
		}

		cmd.rawArgs = append(cmd.rawArgs, rawArg)
		return nil
	}

	for i := 0; ; i++ {
		if !quoted && (i >= len(line) || strings.ContainsRune(argSepChars, rune(line[i]))) {
			// Found arg-separating space.
			if start >= 0 {
				rawArg = append(rawArg, argFragment{s: line[start:i], quoted: false})
				start = -1
			}
			if err := flushArg(); err != nil {
				return nil, err

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Check the offending script line for stray tokens; ensure a real command name is present.
  2. If you see this in practice, inspect the exact line bytes (hidden characters, tabs) since normal spaces should not produce this state.
  3. Report as a parser bug if it reproduces with ordinary input.
Defensive patterns

Strategy: validation

Validate before calling

// Sanity-check that a command token is non-empty before relying on it.
func nonEmptyCommand(name string) error {
    if name == "" { return errors.New("empty command") }
    return nil
}

Type guard

func isEmptyCommand(err error) bool {
    return err != nil && err.Error() == "empty command"
}

Try / catch

// Treat as a parser bug; inspect the exact line bytes if it reproduces.

Prevention

When it happens

Trigger: Reaching this branch requires an unquoted empty token in the command position — a parser edge case rather than a normal user input, since ordinary whitespace collapses and would not produce a standalone empty token. It is primarily a defensive guard for unexpected parser state.

Common situations: Almost never hit by well-formed script input; typically surfaces only with crafted/malformed lines or future parser changes that accidentally yield an empty unquoted name token.

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/d3f26a3307bddc0b. Report an issue: GitHub.