alibaba/nacos · error · Error

Invalid Endpoint URI: ${uri}

Error message

Invalid Endpoint URI: ${uri}

What it means

First of three Invalid Endpoint URI throws in endpointKey. This one fires when `new URL(uri)` itself throws — the input is not parseable as a URL at all (e.g. missing scheme, illegal characters). The URI must be an absolute URL with a scheme and host.

Source

Thrown at console-ui-next/src/pages/newAgent/agent-console-model.ts:148

function optionalString(value: unknown): string | undefined {
  return typeof value === 'string' && value.trim() ? value.trim() : undefined;
}

function validateTransport(value: string): string {
  const transport = required(value, 'transport');
  if (!/^[0-9A-Za-z+-]{1,64}$/.test(transport)) {
    throw new Error('transport must contain 1 to 64 letters, digits, +, or -');
  }
  return transport;
}

function endpointKey(uri: string, transport: string): string {
  let parsed: URL;
  try {
    parsed = new URL(uri);
  } catch {
    throw new Error(`Invalid Endpoint URI: ${uri}`);
  }
  if (!parsed.protocol || !parsed.hostname || parsed.username || parsed.password || parsed.hash) {
    throw new Error(`Invalid Endpoint URI: ${uri}`);
  }
  let port = parsed.port;
  if (!port) {
    if (parsed.protocol === 'http:' || parsed.protocol === 'ws:') {
      port = '80';
    } else if (parsed.protocol === 'https:' || parsed.protocol === 'wss:') {
      port = '443';
    } else {
      throw new Error(`Invalid Endpoint URI: ${uri}`);
    }
  }
  return `${parsed.hostname.toLowerCase()}@@${port}@@${transport}`;
}

function endpointSourceOrder(mode: EndpointSourceMode): AgentCallInterface['endpointSourceOrder'] {

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Provide a full absolute URL with a scheme: 'http://localhost:8080' or 'https://agent.example.com'.
  2. Trim whitespace and strip trailing newlines before submitting.
  3. Prepend 'http://' client-side if the user entered a bare host (confirm intent).

Example fix

// before
uri = 'localhost:8080'

// after
uri = 'http://localhost:8080'
Defensive patterns

Strategy: validation

Validate before calling

function checkAbsoluteUrl(uri) { try { const u = new URL(uri); if (!u.protocol || !u.hostname) throw 0; } catch { throw new Error('Provide a full URL with scheme and host'); } }

Type guard

function isAbsoluteUrl(uri: string): boolean {
  try { const u = new URL(uri); return Boolean(u.protocol && u.hostname); } catch { return false; }
}

Try / catch

try { endpointKey(uri, transport); } catch (e) {
  if (/Invalid Endpoint URI/.test(e.message)) { toast.error('Enter a full URL like https://host:port'); }
}

Prevention

When it happens

Trigger: User enters a bare host like 'localhost:8080' (no protocol), a relative path '/api', or a string with spaces/CRLF. The URL constructor cannot determine the protocol so it rejects the input.

Common situations: User omits the http:// or https:// scheme. User pastes a service name without protocol. Newline or whitespace embedded in the field.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/0092e9078c16b81e. Report an issue: GitHub.