golang/go · error

malformed -http value %q: %v

Error message

malformed -http value %q: %v

What it means

The `-http` flag for `go tool trace` is parsed by `listenAddr`, which calls `net.SplitHostPort`. If the value is not a valid `host:port` (or `:port`) pair, the split fails and the error is wrapped with the offending value. The flag is meant to be a network address to bind the viewer server on.

Source

Thrown at src/cmd/trace/main.go:154

	}

	// Debug flags.
	if *debugFlag != "" {
		switch *debugFlag {
		case "parsed":
			logAndDie(debugProcessedEvents(tracef))
		case "wire":
			logAndDie(debugRawEvents(tracef))
		case "footprint":
			logAndDie(debugEventsFootprint(tracef))
		default:
			logAndDie(fmt.Errorf("invalid debug mode %s, want one of: parsed, wire, footprint", *debugFlag))
		}
	}

	addr, err := listenAddr(*httpFlag)
	if err != nil {
		logAndDie(fmt.Errorf("malformed -http value %q: %v", *httpFlag, err))
	}

	ln, err := net.Listen("tcp", addr)
	if err != nil {
		logAndDie(fmt.Errorf("failed to create server socket: %w", err))
	}

	addr = ln.Addr().String()
	url, simplified, err := addrURL(addr)
	if err != nil {
		logAndDie(fmt.Errorf("failed to compute server URL: %v", err))
	}

	log.Print("Preparing trace for viewer...")
	parsed, err := parseTraceInteractive(tracef, traceSize)
	if err != nil {
		logAndDie(err)
	}

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Pass a host:port pair, e.g. `go tool trace -http=localhost:8080 trace.out`.
  2. To bind an OS-chosen port, use `-http=localhost:0`.
  3. For all-interfaces binding use `-http=:8080` (empty host becomes localhost via listenAddr).

Example fix

// before
$ go tool trace -http=8080 trace.out
// after
$ go tool trace -http=localhost:8080 trace.out
Defensive patterns

Strategy: validation

Validate before calling

if _, _, err := net.SplitHostPort(httpFlag); err != nil {
    return fmt.Errorf("-http must be host:port, got %q", httpFlag)
}

Prevention

When it happens

Trigger: Passing `-http=8080` (missing colon), `-http=foo:bar` (non-numeric port), `-http=:99999` (port out of uint16 range), `-http=localhost:localhost`, or a value with extra whitespace/brackets like `-http=[::1]:80` without the form SplitHostPort expects.

Common situations: Assuming `-http` takes just a port number (it needs `:port`); mirroring an nginx/upstream config format; leftover IPv6 brackets; a shell variable expanding empty producing `-http=: `.

Understand the failure class

Related errors


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