{"record":{"id":"323e65022fdc9379","repo":"JuliusBrussee/caveman","slug":"invalid-listen-address-q-w","errorCode":null,"errorMessage":"invalid listen address %q: %w","messagePattern":"invalid listen address %q: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/runstate/runstate.go","lineNumber":93,"sourceCode":"\tif upstreams == nil {\n\t\treturn nil\n\t}\n\tout := make(map[string]string, len(upstreams))\n\tfor name, raw := range upstreams {\n\t\tout[name] = \"\"\n\t\tu, err := url.Parse(raw)\n\t\tif err != nil || (u.Scheme != \"http\" && u.Scheme != \"https\") || u.Hostname() == \"\" || u.User != nil || u.RawQuery != \"\" || u.ForceQuery || u.Fragment != \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tout[name] = raw\n\t}\n\treturn out\n}\n\nfunc PortFromListen(listen string) (int, error) {\n\t_, raw, err := net.SplitHostPort(listen)\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"invalid listen address %q: %w\", listen, err)\n\t}\n\tport, err := strconv.Atoi(raw)\n\tif err != nil || port < 1 || port > 65535 {\n\t\treturn 0, fmt.Errorf(\"invalid listen port %q\", raw)\n\t}\n\treturn port, nil\n}\n\nfunc Path(home string, port int) string {\n\treturn filepath.Join(home, \"run\", strconv.Itoa(port)+\".json\")\n}\n\nfunc New(listen, mode, owner, version string) (State, error) {\n\tport, err := PortFromListen(listen)\n\tif err != nil {\n\t\treturn State{}, err\n\t}\n\tif owner != \"wrap\" && owner != \"start\" {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/runstate/runstate.go#L75-L111","documentation":"PortFromListen parses a 'host:port' listen address and returns this error when net.SplitHostPort cannot split the string. It means the listen address is not in a recognizable host:port form, so no port can be extracted. The original SplitHostPort error is wrapped for detail.","triggerScenarios":"Passing strings like '8080' (no colon), 'host:port:notaport' (too many colons for a non-bracketed host), '[::1' (unclosed bracket), or an empty string to PortFromListen, or to New/read/runStatus which call it.","commonSituations":"Config files with a bare port number instead of host:port, IPv6 addresses written without brackets, or environment-supplied listen values with typos or stray whitespace.","solutions":["Format the listen address as host:port, e.g. '127.0.0.1:8080' or '[::1]:8080' for IPv6","Wrap IPv6 hosts in square brackets when a port follows","Remove extra colons or whitespace from the listen value","Check the config file/env var that supplies the listen address"],"exampleFix":"// before\nport, err := runstate.PortFromListen(\"8080\")\n// after\nport, err := runstate.PortFromListen(\"127.0.0.1:8080\")","handlingStrategy":"validation","validationCode":"func validListen(s string) bool {\n    _, port, err := net.SplitHostPort(s)\n    if err != nil { return false }\n    p, err := strconv.Atoi(port)\n    return err == nil && p >= 1 && p <= 65535\n}","typeGuard":null,"tryCatchPattern":"port, err := runstate.PortFromListen(listen)\nif err != nil {\n    var addrErr *net.AddrError\n    if errors.As(err, &addrErr) { return fmt.Errorf(\"fix listen %q: %v\", listen, addrErr) }\n    return err\n}","preventionTips":["Always store listen addresses as host:port","Bracket IPv6 hosts: [::1]:8080","Trim whitespace from env/config values before parsing","Validate config at startup with a fail-fast check"],"tags":["config","address-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}