{"record":{"id":"4c4f5b3f61613a47","repo":"jackwener/OpenCLI","slug":"set-opencli-cdp-endpoint-for-example-http-127-0","errorCode":null,"errorMessage":"Set OPENCLI_CDP_ENDPOINT, for example http://127.0.0.1:39240","messagePattern":"Set OPENCLI_CDP_ENDPOINT, for example http://127\\.0\\.0\\.1:39240","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/trae-cn/targets.js","lineNumber":9,"sourceCode":"import { CDPBridge } from '@jackwener/opencli/browser/cdp';\nimport { ArgumentError } from '@jackwener/opencli/errors';\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { activityScript } from './utils.js';\n\nfunction normalizeEndpoint(value) {\n  const endpoint = String(value || process.env.OPENCLI_CDP_ENDPOINT || 'http://127.0.0.1:39240').trim();\n  if (!endpoint) {\n    throw new ArgumentError('Set OPENCLI_CDP_ENDPOINT, for example http://127.0.0.1:39240');\n  }\n  return endpoint.replace(/\\/$/, '');\n}\n\nfunction normalizeBoolean(value, fallback = true) {\n  if (value === undefined || value === null) return fallback;\n  return value === true || String(value).toLowerCase() === 'true';\n}\n\nfunction targetValue(target) {\n  const title = String(target?.title || '').trim();\n  const workspace = title.match(/—\\s*(.+)$/)?.[1]?.trim();\n  return workspace || title || String(target?.url || '').trim();\n}\n\nfunction matchesTarget(target, wanted) {\n  if (!wanted) return false;\n  const needle = String(wanted).toLowerCase();","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/trae-cn/targets.js#L1-L27","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set OPENCLI_CDP_ENDPOINT to a valid URL, e.g. export OPENCLI_CDP_ENDPOINT=http://127.0.0.1:39240.","Omit the --endpoint flag entirely so the default http://127.0.0.1:39240 is used.","Pass a full explicit URL: --endpoint http://127.0.0.1:39240.","Check your shell script for empty variables being passed as --endpoint \"$VAR\"."],"exampleFix":"// before\nOPENCLI_CDP_ENDPOINT=\"\" opencli trae-cn targets --endpoint \"$ENDPOINT\"\n// after\nexport OPENCLI_CDP_ENDPOINT=http://127.0.0.1:39240\nopencli trae-cn targets","handlingStrategy":"validation","validationCode":"function resolveEndpoint(v) {\n  const ep = String(v ?? process.env.OPENCLI_CDP_ENDPOINT ?? 'http://127.0.0.1:39240').trim();\n  if (!ep) throw new Error('OPENCLI_CDP_ENDPOINT is empty; set e.g. http://127.0.0.1:39240');\n  return ep;\n}","typeGuard":"function isValidEndpoint(v) {\n  return typeof v === 'string' && /^https?:\\/\\/[\\w.-]+(:\\d+)?$/.test(v.trim());\n}","tryCatchPattern":"try {\n  const targets = await listTargets();\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('OPENCLI_CDP_ENDPOINT')) {\n    process.env.OPENCLI_CDP_ENDPOINT = 'http://127.0.0.1:39240';\n    return listTargets();\n  }\n  throw e;\n}","preventionTips":["Never pass --endpoint \"\"; omit the flag to use the default.","In scripts, use ${VAR:-http://127.0.0.1:39240} for optional env interpolation.","Assert OPENCLI_CDP_ENDPOINT is non-empty in shell startup/CI setup.","Keep the default port (39240) documented in team runbooks."],"tags":["argument-validation","env-var","cli"],"backgroundTag":"missing-env-var","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}