{"record":{"id":"d0b225bb85160718","repo":"jackwener/OpenCLI","slug":"not-a-username-raw","errorCode":null,"errorMessage":"Not a username: \"${raw}\"","messagePattern":"Not a username: \"(.+?)\"","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/pinterest/utils.js","lineNumber":104,"sourceCode":"        : 'Pass <username>/<slug>, a board URL, or a numeric board id',\n    );\n  }\n  return { username, slug, path: `/${username}/${slug}/` };\n}\n\n/** Normalize a username or profile URL to a bare username (Pinterest has no @-handles). */\nexport function parseUsername(raw) {\n  let value = String(raw ?? '').trim();\n  if (!value) throw new ArgumentError('username is required', 'Pass a Pinterest username or profile URL, e.g. janedoe');\n  if (/^https?:\\/\\//i.test(value)) {\n    try {\n      value = decodeSegment(new URL(value).pathname.split('/').filter(Boolean)[0] || '');\n    } catch {\n      throw new ArgumentError(`Invalid profile URL: ${raw}`, 'Use a full profile URL like https://www.pinterest.com/janedoe/');\n    }\n  }\n  value = value.replace(/^\\/+|\\/+$/g, '');\n  if (!value) throw new ArgumentError(`Not a username: \"${raw}\"`, 'Pass the bare username, e.g. janedoe');\n  if (value.includes('/')) {\n    throw new ArgumentError(\n      `Not a username: \"${raw}\"`,\n      'This looks like a board or pin reference — pass just the username, e.g. janedoe',\n    );\n  }\n  if (value.startsWith('@')) {\n    throw new ArgumentError(`Pinterest usernames have no \"@\": \"${raw}\"`, 'Drop the @ and use the bare username, e.g. janedoe');\n  }\n  return value;\n}\n\n/** Parse a bare pin id or a /pin/<id>/ URL. */\nexport function parsePinId(raw) {\n  const value = String(raw ?? '').trim();\n  if (!value) throw new ArgumentError('pin id is required', 'Pass a pin id or /pin/<id>/ URL, e.g. 1234567890123456');\n  if (/^\\d+$/.test(value)) return value;\n  const match = value.match(/\\/pin\\/(\\d+)/);","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pinterest/utils.js#L86-L122","documentation":"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.","triggerScenarios":"Calling parseUsername('/'), parseUsername('///'), or a URL like 'https://www.pinterest.com/' whose pathname has no segments after decoding/filtering.","commonSituations":"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 '/'.","solutions":["Pass the bare username, e.g. janedoe","If using a URL, include the profile path: https://www.pinterest.com/janedoe/","Verify the variable isn't defaulting to '/' or the site root","Add a check that the extracted segment is non-empty before calling"],"exampleFix":"// before\nconst user = parseUsername('https://www.pinterest.com/');\n// after\nconst user = parseUsername('https://www.pinterest.com/janedoe/');","handlingStrategy":"validation","validationCode":"const seg = String(input || '').split('/').filter(Boolean)[0];\nif (!seg) throw new Error('No username derivable from input: ' + input);","typeGuard":"const yieldsUsername = (v) => String(v ?? '').split('/').filter(Boolean).length > 0;","tryCatchPattern":"try {\n  username = parseUsername(input);\n} catch (err) {\n  if (err instanceof ArgumentError && /Not a username/.test(err.message)) {\n    console.error(`${err.message} — ${err.hint}`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Don't pass bare domains or homepage URLs where a username is expected","Check that config values aren't defaulting to '/' or a base URL","Filter out empty path segments before constructing username inputs","Log the exact value passed when automation fails, to spot empty reductions"],"tags":["validation","argument-error","empty-input","username"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}