jackwener/OpenCLI · error · ArgumentError

pin id is required

Error message

pin id is required

What it means

parsePinId parses a bare numeric pin id or a /pin/<id>/ URL into a pin id string. It throws this ArgumentError when the input is empty or whitespace-only, since there is no id to extract. Failing fast avoids issuing a request to an undefined pin endpoint.

Source

Thrown at clis/pinterest/utils.js:120

  }
  value = value.replace(/^\/+|\/+$/g, '');
  if (!value) throw new ArgumentError(`Not a username: "${raw}"`, 'Pass the bare username, e.g. janedoe');
  if (value.includes('/')) {
    throw new ArgumentError(
      `Not a username: "${raw}"`,
      'This looks like a board or pin reference — pass just the username, e.g. janedoe',
    );
  }
  if (value.startsWith('@')) {
    throw new ArgumentError(`Pinterest usernames have no "@": "${raw}"`, 'Drop the @ and use the bare username, e.g. janedoe');
  }
  return value;
}

/** Parse a bare pin id or a /pin/<id>/ URL. */
export function parsePinId(raw) {
  const value = String(raw ?? '').trim();
  if (!value) throw new ArgumentError('pin id is required', 'Pass a pin id or /pin/<id>/ URL, e.g. 1234567890123456');
  if (/^\d+$/.test(value)) return value;
  const match = value.match(/\/pin\/(\d+)/);
  if (match) return match[1];
  throw new ArgumentError(`Not a pin id or pin URL: "${raw}"`, 'Expected a numeric id or a /pin/<id>/ URL, e.g. 1234567890123456');
}

/** Highest-resolution image URL available for a pin. */
export function pickPinImage(images) {
  if (!images || typeof images !== 'object') return '';
  for (const key of ['orig', '736x', '564x', '474x', '236x']) {
    const candidate = images[key];
    if (candidate && candidate.url) return candidate.url;
  }
  return '';
}

/** Map a raw pin to the shared grid-row shape used by list commands. */
export function toPinRow(pin) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a numeric pin id, e.g. 1234567890123456
  2. Or pass a /pin/<id>/ URL like https://www.pinterest.com/pin/1234567890123456/
  3. Verify the upstream data/config actually contains the pin id before calling
  4. Add an early existence check and skip/handle rows with missing ids

Example fix

// before
const id = parsePinId(row.pinId); // may be ''
// after
if (!row.pinId) { console.warn('skipping row without pinId'); return; }
const id = parsePinId(row.pinId);
Defensive patterns

Strategy: validation

Validate before calling

const id = String(raw ?? '').trim();
if (!id) throw new Error('pin id missing');
const isPinRef = /^\d+$/.test(id) || /\/pin\/(\d+)/.test(id);
if (!isPinRef) throw new Error(`not a pin id or pin URL: ${id}`);

Type guard

const isPinIdLike = (v) => {
  const s = String(v ?? '').trim();
  return /^\d+$/.test(s) || /\/pin\/(\d+)/.test(s);
};

Try / catch

let pinId;
try {
  pinId = parsePinId(input);
} catch (err) {
  if (err instanceof ArgumentError && err.message === 'pin id is required') {
    console.error('Usage: ... <pinId|pin-url>');
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling parsePinId(''), parsePinId(null), parsePinId(undefined), or parsePinId(' ') — e.g. an id/sourcePinId argument that was never provided.

Common situations: Forgot to pass the pin id to the CLI command; an upstream lookup returned nothing so the variable was empty; JSON config key missing so undefined was passed; a script loop where one row lacked an id.

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/881968eae771e53c. Report an issue: GitHub.