jackwener/OpenCLI · error · ArgumentError

Not a username: "${raw}"

Error message

Not a username: "${raw}"

What it means

After trimming slashes, parseUsername throws this ArgumentError when nothing remains — i.e. the input reduced to an empty value (for example a lone '/' or '///'). It means the library could not extract any username from the input. Thrown with guidance to pass the bare username.

Source

Thrown at clis/pinterest/utils.js:104

        : 'Pass <username>/<slug>, a board URL, or a numeric board id',
    );
  }
  return { username, slug, path: `/${username}/${slug}/` };
}

/** Normalize a username or profile URL to a bare username (Pinterest has no @-handles). */
export function parseUsername(raw) {
  let value = String(raw ?? '').trim();
  if (!value) throw new ArgumentError('username is required', 'Pass a Pinterest username or profile URL, e.g. janedoe');
  if (/^https?:\/\//i.test(value)) {
    try {
      value = decodeSegment(new URL(value).pathname.split('/').filter(Boolean)[0] || '');
    } catch {
      throw new ArgumentError(`Invalid profile URL: ${raw}`, 'Use a full profile URL like https://www.pinterest.com/janedoe/');
    }
  }
  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+)/);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass the bare username, e.g. janedoe
  2. If using a URL, include the profile path: https://www.pinterest.com/janedoe/
  3. Verify the variable isn't defaulting to '/' or the site root
  4. Add a check that the extracted segment is non-empty before calling

Example fix

// before
const user = parseUsername('https://www.pinterest.com/');
// after
const user = parseUsername('https://www.pinterest.com/janedoe/');
Defensive patterns

Strategy: validation

Validate before calling

const seg = String(input || '').split('/').filter(Boolean)[0];
if (!seg) throw new Error('No username derivable from input: ' + input);

Type guard

const yieldsUsername = (v) => String(v ?? '').split('/').filter(Boolean).length > 0;

Try / catch

try {
  username = parseUsername(input);
} catch (err) {
  if (err instanceof ArgumentError && /Not a username/.test(err.message)) {
    console.error(`${err.message} — ${err.hint}`);
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Calling parseUsername('/'), parseUsername('///'), or a URL like 'https://www.pinterest.com/' whose pathname has no segments after decoding/filtering.

Common situations: Pasting the Pinterest homepage URL instead of a profile URL; a base-URL-only config value passed where a username was expected; shell variable expanding to '/'.

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