{"record":{"id":"397a583e6b713ef7","repo":"github/copilot-sdk","slug":"invalid-port-in-cli-url-url","errorCode":null,"errorMessage":"Invalid port in cli_url: {url}","messagePattern":"Invalid port in cli_url: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/copilot/client.py","lineNumber":1861,"sourceCode":"        Supports formats: \"host:port\", \"[ipv6]:port\", \"http://host:port\",\n        \"https://host:port\", or just \"port\".\n\n        Args:\n            url: The CLI URL to parse.\n\n        Returns:\n            A tuple of (host, port).\n\n        Raises:\n            ValueError: If the URL format is invalid or the port is out of range.\n        \"\"\"\n        clean_url = re.sub(r\"^https?://\", \"\", url)\n\n        # Check if it's just a port number\n        if clean_url.isdigit():\n            port = int(clean_url)\n            if port <= 0 or port > 65535:\n                raise ValueError(f\"Invalid port in cli_url: {url}\")\n            return (\"localhost\", port)\n\n        ipv6_match = re.match(r\"^\\[([^\\]]+)\\]:(.*)$\", clean_url)\n        if ipv6_match:\n            host = ipv6_match.group(1)\n            port_text = ipv6_match.group(2)\n            try:\n                ipaddress.IPv6Address(host)\n            except ValueError as e:\n                raise ValueError(f\"Invalid cli_url format: {url}\") from e\n        else:\n            # Parse host:port format\n            parts = clean_url.split(\":\")\n            if len(parts) != 2:\n                raise ValueError(f\"Invalid cli_url format: {url}\")\n            host = parts[0] if parts[0] else \"localhost\"\n            port_text = parts[1]\n","sourceCodeStart":1843,"sourceCodeEnd":1879,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/python/copilot/client.py#L1843-L1879","documentation":"This ValueError comes from the cli_url parser when the URL is a bare port number (e.g. 'http://99999' or '99999'). After stripping the scheme, digits are interpreted as a port, and the code validates it must be in 1..65535. Ports outside that range cannot be bound, so the parser rejects them up front.","triggerScenarios":"Passing `cli_url='http://0'`, `'http://70000'`, `'-1'`, or any numeric string outside 1-65535 to CopilotClient or the CLI URL option.","commonSituations":"See trigger scenarios.","solutions":["Use a valid port between 1 and 65535, e.g. cli_url='http://localhost:4242'.","If the value should be a full host:port, supply it in that form instead of just a number.","Validate the port range in config loading before constructing the client."],"exampleFix":"// before\nclient = CopilotClient(cli_url=\"http://70000\")\n// after\nclient = CopilotClient(cli_url=\"http://localhost:4242\")","handlingStrategy":"validation","validationCode":"def validate_cli_url(url: str) -> None:\n    clean = re.sub(r\"^https?://\", \"\", url)\n    if clean.isdigit() and not (1 <= int(clean) <= 65535):\n        raise ValueError(f\"port out of range: {url}\")","typeGuard":null,"tryCatchPattern":"try:\n    client = CopilotClient(cli_url=url)\nexcept ValueError as e:\n    if \"Invalid port\" in str(e):\n        raise ConfigError(f\"cli_url port must be 1-65535: {url}\") from e\n    raise","preventionTips":["Validate ports against 1-65535 when loading config","Never use 0 or -1 as placeholder ports","Prefer full host:port URLs over bare port numbers"],"tags":["python","config","url-parsing","port"],"backgroundTag":"value-out-of-range","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"}