jackwener/OpenCLI · error · ArgumentError

Set OPENCLI_CDP_ENDPOINT, for example http://127.0.0.1:39240

Error message

Set OPENCLI_CDP_ENDPOINT, for example http://127.0.0.1:39240

What it means

normalizeEndpoint in targets.js throws an ArgumentError when the endpoint value resolves to an empty string after falling through the CLI value, OPENCLI_CDP_ENDPOINT env var, and the default 'http://127.0.0.1:39240'. This happens only when a caller explicitly passes an empty/whitespace value that overrides the defaults.

Source

Thrown at clis/trae-cn/targets.js:9

import { CDPBridge } from '@jackwener/opencli/browser/cdp';
import { ArgumentError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { activityScript } from './utils.js';

function normalizeEndpoint(value) {
  const endpoint = String(value || process.env.OPENCLI_CDP_ENDPOINT || 'http://127.0.0.1:39240').trim();
  if (!endpoint) {
    throw new ArgumentError('Set OPENCLI_CDP_ENDPOINT, for example http://127.0.0.1:39240');
  }
  return endpoint.replace(/\/$/, '');
}

function normalizeBoolean(value, fallback = true) {
  if (value === undefined || value === null) return fallback;
  return value === true || String(value).toLowerCase() === 'true';
}

function targetValue(target) {
  const title = String(target?.title || '').trim();
  const workspace = title.match(/—\s*(.+)$/)?.[1]?.trim();
  return workspace || title || String(target?.url || '').trim();
}

function matchesTarget(target, wanted) {
  if (!wanted) return false;
  const needle = String(wanted).toLowerCase();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Set OPENCLI_CDP_ENDPOINT to a valid URL, e.g. export OPENCLI_CDP_ENDPOINT=http://127.0.0.1:39240.
  2. Omit the --endpoint flag entirely so the default http://127.0.0.1:39240 is used.
  3. Pass a full explicit URL: --endpoint http://127.0.0.1:39240.
  4. Check your shell script for empty variables being passed as --endpoint "$VAR".

Example fix

// before
OPENCLI_CDP_ENDPOINT="" opencli trae-cn targets --endpoint "$ENDPOINT"
// after
export OPENCLI_CDP_ENDPOINT=http://127.0.0.1:39240
opencli trae-cn targets
Defensive patterns

Strategy: validation

Validate before calling

function resolveEndpoint(v) {
  const ep = String(v ?? process.env.OPENCLI_CDP_ENDPOINT ?? 'http://127.0.0.1:39240').trim();
  if (!ep) throw new Error('OPENCLI_CDP_ENDPOINT is empty; set e.g. http://127.0.0.1:39240');
  return ep;
}

Type guard

function isValidEndpoint(v) {
  return typeof v === 'string' && /^https?:\/\/[\w.-]+(:\d+)?$/.test(v.trim());
}

Try / catch

try {
  const targets = await listTargets();
} catch (e) {
  if (e instanceof ArgumentError && e.message.includes('OPENCLI_CDP_ENDPOINT')) {
    process.env.OPENCLI_CDP_ENDPOINT = 'http://127.0.0.1:39240';
    return listTargets();
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking a command with an explicit empty endpoint (e.g. `--endpoint ""` or `--endpoint " "`), or OPENCLI_CDP_ENDPOINT='' combined with a CLI flag passing an empty string, so String(value||...) yields '' after trim.

Common situations: Shell script with an unset variable interpolated as an empty --endpoint argument; CI config where OPENCLI_CDP_ENDPOINT is defined but blank; copy-pasted command missing the URL.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/4c4f5b3f61613a47. Report an issue: GitHub.