jackwener/OpenCLI · error · CommandExecutionError

LinkedIn company requires a company universal name or URL

Error message

LinkedIn company requires a company universal name or URL

What it means

normalizeCompanyUrl validates its input before building the company about-page URL: after whitespace normalization an empty string is rejected with CommandExecutionError. The library requires either a bare universal name (e.g. 'nvidia'), a /company/<slug> path, or a full LinkedIn company URL.

Source

Thrown at clis/linkedin/company.js:19

import { cli, Strategy } from '@jackwener/opencli/registry';
import { CommandExecutionError } from '@jackwener/opencli/errors';
import {
    LINKEDIN_DOMAIN,
    assertLinkedInAuthenticated,
    normalizeWhitespace,
    unwrapEvaluateResult,
} from './shared.js';

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]}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the company universal name or URL, e.g. `linkedin company nvidia` or https://www.linkedin.com/company/nvidia/.
  2. Validate the argument is a non-empty string before invoking the command.
  3. Fix the upstream data source emitting empty values (env var, config, CSV column).

Example fix

// before
const name = process.env.COMPANY; // ''
await run(`linkedin company ${name}`); // throws
// after
if (!process.env.COMPANY) throw new Error('COMPANY env var required');
await run(`linkedin company ${process.env.COMPANY}`);
Defensive patterns

Strategy: validation

Validate before calling

function requireCompanyInput(value) {
  const v = (value || '').trim();
  if (!v) throw new Error('company universal name or URL required');
  return v;
}
await run(`linkedin company ${requireCompanyInput(arg)}`);

Type guard

function hasCompanyInput(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await run(`linkedin company ${arg}`);
} catch (e) {
  if (/requires a company universal name or URL/.test(e.message)) {
    throw new UsageError('Usage: linkedin company <slug|url>');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the linkedin company command/targetUrl with an empty, whitespace-only, or undefined argument (e.g. missing CLI arg, variable that resolved to empty string).

Common situations: Script passing an empty env var or unbound lookup result; forgetting the positional CLI argument; upstream data pipeline emitting blank company fields.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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