{"record":{"id":"516df76866cd3f42","repo":"golang/go","slug":"malformed-http-value-q-v","errorCode":null,"errorMessage":"malformed -http value %q: %v","messagePattern":"malformed -http value %q: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/trace/main.go","lineNumber":154,"sourceCode":"\t}\n\n\t// Debug flags.\n\tif *debugFlag != \"\" {\n\t\tswitch *debugFlag {\n\t\tcase \"parsed\":\n\t\t\tlogAndDie(debugProcessedEvents(tracef))\n\t\tcase \"wire\":\n\t\t\tlogAndDie(debugRawEvents(tracef))\n\t\tcase \"footprint\":\n\t\t\tlogAndDie(debugEventsFootprint(tracef))\n\t\tdefault:\n\t\t\tlogAndDie(fmt.Errorf(\"invalid debug mode %s, want one of: parsed, wire, footprint\", *debugFlag))\n\t\t}\n\t}\n\n\taddr, err := listenAddr(*httpFlag)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"malformed -http value %q: %v\", *httpFlag, err))\n\t}\n\n\tln, err := net.Listen(\"tcp\", addr)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to create server socket: %w\", err))\n\t}\n\n\taddr = ln.Addr().String()\n\turl, simplified, err := addrURL(addr)\n\tif err != nil {\n\t\tlogAndDie(fmt.Errorf(\"failed to compute server URL: %v\", err))\n\t}\n\n\tlog.Print(\"Preparing trace for viewer...\")\n\tparsed, err := parseTraceInteractive(tracef, traceSize)\n\tif err != nil {\n\t\tlogAndDie(err)\n\t}","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/trace/main.go#L136-L172","documentation":"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.","triggerScenarios":"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.","commonSituations":"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=: `.","solutions":["Pass a host:port pair, e.g. `go tool trace -http=localhost:8080 trace.out`.","To bind an OS-chosen port, use `-http=localhost:0`.","For all-interfaces binding use `-http=:8080` (empty host becomes localhost via listenAddr)."],"exampleFix":"// before\n$ go tool trace -http=8080 trace.out\n// after\n$ go tool trace -http=localhost:8080 trace.out","handlingStrategy":"validation","validationCode":"if _, _, err := net.SplitHostPort(httpFlag); err != nil {\n    return fmt.Errorf(\"-http must be host:port, got %q\", httpFlag)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass -http as host:port (use :0 for a random port).","Document the address format in your team's trace-viewer runbook."],"tags":["cli","go-tool-trace","network","argument-validation"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}