golang/go · error

missing key=value

Error message

missing key=value

What it means

A //go:debug directive in a Go source file consists of the marker '//go:debug' with no whitespace-separated arguments at all. The directive requires at least one key=value pair. This specific variant fires when strings.IndexAny(text, " \t") returns -1 (no space or tab after the prefix) and strings.TrimSpace(text) equals exactly '//go:debug', meaning the line is just the bare directive with nothing following.

Source

Thrown at src/cmd/go/internal/load/godebug.go:31

	"sort"
	"strconv"
	"strings"

	"cmd/go/internal/fips140"
	"cmd/go/internal/gover"
	"cmd/go/internal/modload"
)

var ErrNotGoDebug = errors.New("not //go:debug line")

func ParseGoDebug(text string) (key, value string, err error) {
	if !strings.HasPrefix(text, "//go:debug") {
		return "", "", ErrNotGoDebug
	}
	i := strings.IndexAny(text, " \t")
	if i < 0 {
		if strings.TrimSpace(text) == "//go:debug" {
			return "", "", fmt.Errorf("missing key=value")
		}
		return "", "", ErrNotGoDebug
	}
	k, v, ok := strings.Cut(strings.TrimSpace(text[i:]), "=")
	if !ok {
		return "", "", fmt.Errorf("missing key=value")
	}
	if err := modload.CheckGodebug("//go:debug setting", k, v); err != nil {
		return "", "", err
	}
	return k, v, nil
}

func defaultGODEBUGGoVersion(ld *modload.Loader, p *Package) string {
	if !ld.Enabled() {
		// GOPATH mode. Use Go 1.20.
		return "1.20"
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Add a key=value pair after the directive: //go:debug panicnil=1.
  2. Look up valid GODEBUG keys in the Go documentation (e.g., panicnil, http2client, etc.).
  3. If you don't need the directive, remove the line entirely — an absent directive is not an error.

Example fix

// before — empty directive with no arguments
//go:debug
// after — valid key=value pair
//go:debug panicnil=1
Defensive patterns

Strategy: validation

Validate before calling

// Validate //go:debug directive has at least one key=value argument.
func validateGoDebug(text string) error {
    if !strings.HasPrefix(text, "//go:debug") {
        return nil // not a go:debug line
    }
    rest := strings.TrimSpace(strings.TrimPrefix(text, "//go:debug"))
    if rest == "" {
        return fmt.Errorf("//go:debug directive has no key=value pair")
    }
    return nil
}

Prevention

When it happens

Trigger: Adding '//go:debug' to a Go source file (typically in the main package) with no arguments after it. The ParseGoDebug function finds no whitespace separator and the trimmed text is just the directive marker.

Common situations: Writing a //go:debug directive without knowing the required key=value syntax. Template-generated directives that leave the value empty. Accidentally truncating the directive during editing. Copy-pasting from incomplete examples.

Related errors


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