{"record":{"id":"00c813d6d6e5854b","repo":"github/copilot-sdk","slug":"invalid-port-in-uriconnection-s","errorCode":null,"errorMessage":"Invalid port in URIConnection: %s","messagePattern":"Invalid port in URIConnection: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":417,"sourceCode":"\t}\n\treturn append(filtered, key+\"=\"+value)\n}\n\n// parseCLIURL parses a CLI URL into host and port components.\n//\n// Supports formats: \"host:port\", \"[ipv6]:port\", \"http://host:port\", \"https://host:port\", or just \"port\".\n// Panics if the URL format is invalid or the port is out of range.\nfunc parseCLIURL(url string) (string, int) {\n\t// Remove protocol if present\n\tcleanURL, _ := strings.CutPrefix(url, \"https://\")\n\tcleanURL, _ = strings.CutPrefix(cleanURL, \"http://\")\n\n\t// Use the standard parser only for the bracketed IPv6 form. Keep the\n\t// existing host:port parsing behavior for all other inputs.\n\tif strings.HasPrefix(cleanURL, \"[\") {\n\t\thost, portStr, err := net.SplitHostPort(cleanURL)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Sprintf(\"Invalid port in URIConnection: %s\", url))\n\t\t}\n\t\taddr, err := netip.ParseAddr(host)\n\t\tif err != nil || !addr.Is6() {\n\t\t\tpanic(fmt.Sprintf(\"Invalid URIConnection format: %s\", url))\n\t\t}\n\t\tport, err := strconv.Atoi(portStr)\n\t\tif err != nil || port <= 0 || port > 65535 {\n\t\t\tpanic(fmt.Sprintf(\"Invalid port in URIConnection: %s\", url))\n\t\t}\n\t\treturn host, port\n\t}\n\n\t// Parse host:port or port format\n\tvar host string\n\tvar portStr string\n\tif before, after, found := strings.Cut(cleanURL, \":\"); found {\n\t\thost = before\n\t\tportStr = after","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L399-L435","documentation":"parseCLIURL panics with \"Invalid port in URIConnection: %s\" when a bracketed IPv6 URIConnection URL cannot be split into host and port (net.SplitHostPort fails). This means the URL is malformed for the bracketed-IPv6 form the parser supports, e.g. missing the port or unbalanced brackets.","triggerScenarios":"Passing URIConnection{URL: \"[::1]\"} or \"[::1]:\" or otherwise malformed bracketed IPv6 input to NewClient; parseCLIURL is invoked from NewClient when handling a URIConnection. Panic at go/client.go:417.","commonSituations":"Hand-assembling IPv6 URLs without brackets/port; templating a host into a URL string where the port segment is lost; IPv6 literals from environment config missing the [host]:port form.","solutions":["Use the full bracketed form with a port, e.g. \"http://[::1]:4141\".","Validate the URL with net.SplitHostPort / url.Parse before constructing the client.","If only the host is known, format it explicitly: fmt.Sprintf(\"http://[%s]:%d\", host, port)."],"exampleFix":"// before\nclient := clientpkg.NewClient(&clientpkg.Options{\n    Connection: clientpkg.URIConnection{URL: \"[::1]\"}, // no port\n})\n// after\nclient := clientpkg.NewClient(&clientpkg.Options{\n    Connection: clientpkg.URIConnection{URL: \"http://[::1]:4141\"},\n})","handlingStrategy":"validation","validationCode":"if strings.HasPrefix(u, \"[\") {\n    if _, _, err := net.SplitHostPort(u); err != nil {\n        return fmt.Errorf(\"malformed bracketed IPv6 URL %q (need [host]:port)\", u)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always format IPv6 hosts as [host]:port, including the port.","Build URLs with url.URL or fmt.Sprintf rather than string concatenation.","Smoke-test URIConnection URLs with net.SplitHostPort before passing them to NewClient."],"tags":["go","panic","url","ipv6","parsing"],"backgroundTag":"invalid-url-format","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}