{"record":{"id":"9570060021efd150","repo":"jackwener/OpenCLI","slug":"username-is-required-957006","errorCode":null,"errorMessage":"username is required","messagePattern":"username is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/pinterest/utils.js","lineNumber":95,"sourceCode":"  // Pinterest percent-encodes non-ASCII slugs in the URLs it hands out; the API wants them decoded.\n  const parts = pathname.split('/').filter(Boolean).map(decodeSegment);\n  if (parts.length < 2) return null;\n  const [username, slug] = parts;\n  if (RESERVED_PATH_ROOTS.has(username.toLowerCase())) {\n    throw new ArgumentError(\n      `\"${raw}\" is a Pinterest /${username}/ URL, not a board`,\n      username.toLowerCase() === 'pin'\n        ? 'Pass the board this pin lives on, e.g. janedoe/my-board (`opencli pinterest pin <id>` reports it)'\n        : '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  }","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pinterest/utils.js#L77-L113","documentation":"parseUsername normalizes a username or profile URL to a bare Pinterest username (Pinterest has no @-handles). It throws this ArgumentError when the raw input is empty or whitespace-only after String coercion, since no username can be derived. This fails fast instead of issuing an API request with a blank path segment.","triggerScenarios":"Calling parseUsername(''), parseUsername(null), parseUsername(undefined), or parseUsername('   ') — either directly or through a username command whose argument was omitted.","commonSituations":"Forgot to pass the CLI argument; an env var like $PINTEREST_USER was unset so the shell substituted nothing; a script variable defaulted to an empty string.","solutions":["Pass a Pinterest username or profile URL, e.g. janedoe or https://www.pinterest.com/janedoe/","Check that the environment variable / config key supplying the username is actually set","Trim the value before calling so whitespace-only input is caught as a config bug","Add an early guard in your script that errors when the username variable is empty"],"exampleFix":"// before\nconst user = parseUsername(process.env.PINTEREST_USER);\n// after\nconst raw = process.env.PINTEREST_USER;\nif (!raw || !raw.trim()) throw new Error('Set PINTEREST_USER first');\nconst user = parseUsername(raw);","handlingStrategy":"validation","validationCode":"const raw = process.env.PINTEREST_USER;\nif (!raw || !raw.trim()) {\n  throw new Error('PINTEREST_USER is not set');\n}","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"let username;\ntry {\n  username = parseUsername(input);\n} catch (err) {\n  if (err instanceof ArgumentError && err.message === 'username is required') {\n    console.error('Usage: ... <username|profile-url>');\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Make the username a required CLI argument so omission fails at argument parsing","Verify env vars are exported in shell profiles and CI secrets","Default empty config values loudly at startup, not deep in a call","Use ${VAR:?msg} in shell scripts to catch unset variables"],"tags":["validation","argument-error","missing-argument","username"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}