github/copilot-sdk · error

Invalid cliUrl format

Error message

Invalid cliUrl format: ${url}

What it means

parseCliUrl rejected the cliUrl string: inside a bracketed [ ... ]:port form, the host segment did not pass the isIPv6 check. The parser accepts 'host:port', '[ipv6]:port', 'http(s)://host:port', or a bare port; anything else — here specifically a malformed bracketed IPv6 host — triggers this throw.

Solutions

  1. Use a valid IPv6 literal in brackets, e.g. '[::1]:8080'
  2. Drop the brackets if the host is a hostname or IPv4, e.g. 'localhost:8080'
  3. Verify the URL was not truncated or mangled by shell/config interpolation before reaching the parser
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at nodejs/src/client.ts:770 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/eff39c9bfe0a7f25. Report an issue: GitHub.

Appendix: source

Thrown at nodejs/src/client.ts:770

     * Parse CLI URL into host and port
     * Supports formats: "host:port", "[ipv6]:port", "http://host:port", "https://host:port", or just "port"
     */
    private parseCliUrl(url: string): { host: string; port: number } {
        // Remove protocol if present
        const cleanUrl = url.replace(/^https?:\/\//, "");

        // Check if it's just a port number
        if (/^\d+$/.test(cleanUrl)) {
            return { host: "localhost", port: parseInt(cleanUrl, 10) };
        }

        // Handle the canonical bracketed IPv6 host:port form without changing
        // the existing parser behavior for other inputs.
        const ipv6Match = cleanUrl.match(/^\[([^\]]+)\]:(\d+)$/);
        if (ipv6Match) {
            const host = ipv6Match[1];
            if (!isIPv6(host)) {
                throw new Error(`Invalid cliUrl format: ${url}`);
            }

            const port = parseInt(ipv6Match[2], 10);
            if (isNaN(port) || port <= 0 || port > 65535) {
                throw new Error(`Invalid port in cliUrl: ${url}`);
            }
            return { host, port };
        }

        // Parse host:port format
        const parts = cleanUrl.split(":");
        if (parts.length !== 2) {
            throw new Error(
                `Invalid cliUrl format: ${url}. Expected "host:port", "[ipv6]:port", "http://host:port", or "port"`
            );
        }

        const host = parts[0] || "localhost";

View on GitHub (pinned to cd8cf15dc3)