jackwener/OpenCLI · error · CommandExecutionError

LinkedIn company received a malformed URL: ${raw}

Error message

LinkedIn company received a malformed URL: ${raw}

What it means

When the input looks like a URL (http(s):// or /company/ prefix) the library parses it with the URL constructor; if parsing throws (or the earlier structural checks fail), normalizeCompanyUrl rejects it with CommandExecutionError naming the raw input. It guards the URL-building step from garbage input.

Source

Thrown at clis/linkedin/company.js:27

const SLUG_RE = /^[A-Za-z0-9%._-]+$/;
const COMPANY_URL_RE = /^\/company\/([^/?#]+)/;
const LINKEDIN_COMPANY_HOSTS = new Set(['linkedin.com', LINKEDIN_DOMAIN]);

// Accept a bare universal name (`nvidia`), a `/company/<slug>` path, or a full
// company URL, and return the canonical about-page URL.
function normalizeCompanyUrl(value) {
    const raw = normalizeWhitespace(value || '');
    if (!raw) {
        throw new CommandExecutionError('LinkedIn company requires a company universal name or URL');
    }
    let slug = raw;
    if (/^https?:\/\//i.test(raw) || raw.startsWith('/company/')) {
        let parsed;
        try {
            parsed = raw.startsWith('/') ? new URL(raw, `https://${LINKEDIN_DOMAIN}`) : new URL(raw);
        } catch {
            throw new CommandExecutionError(`LinkedIn company received a malformed URL: ${raw}`);
        }
        if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || !LINKEDIN_COMPANY_HOSTS.has(parsed.hostname.toLowerCase())) {
            throw new CommandExecutionError('LinkedIn company URL must point to linkedin.com');
        }
        const m = parsed.pathname.match(COMPANY_URL_RE);
        if (!m) throw new CommandExecutionError('LinkedIn company URL must look like /company/<name>');
        try {
            slug = decodeURIComponent(m[1]);
        } catch {
            throw new CommandExecutionError(`LinkedIn company URL has a malformed company slug: ${m[1]}`);
        }
    }
    if (!SLUG_RE.test(slug)) {
        throw new CommandExecutionError(`LinkedIn company name has unexpected characters: ${slug}`);
    }
    return `https://www.linkedin.com/company/${encodeURIComponent(slug)}/about/`;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Correct the URL in your input — it must parse, e.g. https://www.linkedin.com/company/nvidia/.
  2. Pre-validate with `new URL(value, 'https://www.linkedin.com')` in a try/catch before calling.
  3. If you meant a bare universal name, pass just the slug ('nvidia') instead of a malformed URL.
  4. Trim/sanitize the value (strip quotes, brackets, embedded whitespace) before invoking.

Example fix

// before
await run('linkedin company "https://www.linkedin.com/company/nvidia'); // malformed
// after
const url = raw.trim().replace(/"/g, '');
try { new URL(url, 'https://www.linkedin.com'); } catch { return fallback; }
await run(`linkedin company ${url}`);
Defensive patterns

Strategy: validation

Validate before calling

function safeCompanyUrl(raw) {
  const v = String(raw || '').trim().replace(/["']/g, '');
  try { new URL(v.startsWith('/') ? v : v, 'https://www.linkedin.com'); }
  catch { throw new Error(`malformed LinkedIn company URL: ${v}`); }
  return v;
}

Type guard

function isParseableUrl(v) {
  try { new URL(v, 'https://www.linkedin.com'); return true; } catch { return false; }
}

Try / catch

try {
  await run(`linkedin company ${raw}`);
} catch (e) {
  if (/malformed URL/.test(e.message)) {
    // sanitize or fall back to bare slug form
    return run(`linkedin company ${raw.replace(/[^\w./:-]/g, '')}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Passing a URL-looking string that new URL() cannot parse — e.g. 'http://', 'https://[bad', or a value the caller believed was a URL but contains stray characters/whitespace embedded mid-string.

Common situations: Copy-pasted URLs with typos or truncated protocol; data pipelines concatenating fields incorrectly; single quotes/brackets from template strings leaking into the URL; a slug like 'nvidia inc' that starts with '/' by mistake.

Understand the failure class

Related errors


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