{"record":{"id":"f9169a2dde4c0d67","repo":"jackwener/OpenCLI","slug":"label-is-required-f9169a","errorCode":null,"errorMessage":"${label} is required","messagePattern":"(.+?) is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/shared.js","lineNumber":107,"sourceCode":"  let parsed;\n  try {\n    parsed = new URL(raw, 'https://www.linkedin.com');\n  } catch {\n    throw new ArgumentError(`${label} must be a LinkedIn URL`);\n  }\n  const host = parsed.hostname.toLowerCase();\n  if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port) {\n    throw new ArgumentError(`${label} must be an https LinkedIn URL without credentials or port`);\n  }\n  if (host !== 'linkedin.com' && host !== 'www.linkedin.com') {\n    throw new ArgumentError(`${label} must point to linkedin.com`);\n  }\n  return parsed.toString();\n}\n\nexport function requireStringArg(args, key, label = key) {\n  const value = normalizeWhitespace(args?.[key]);\n  if (!value) throw new ArgumentError(`${label} is required`);\n  return value;\n}\n\nexport function parseLimit(value, fallback, max) {\n  if (value === undefined || value === null || value === '') return fallback;\n  const parsed = Number(value);\n  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {\n    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);\n  }\n  return parsed;\n}\n\nexport async function requireLinkedInCookie(page, context) {\n  let cookies;\n  try {\n    cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n  } catch (error) {\n    throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/shared.js#L89-L125","documentation":"requireStringArg normalizes whitespace on args[key] and throws ArgumentError when the resulting value is empty or missing. It guarantees required CLI arguments are present before command logic runs.","triggerScenarios":"Invoking a command without the required flag, or passing it as an empty/whitespace-only string, e.g. `linkedin url --url \"\"` or omitting --url entirely.","commonSituations":"Scripted/CI invocations where an env var feeding the flag is unset or empty, copy-paste dropped the flag value, or quoting issues leave the argument blank.","solutions":["Pass the required argument: e.g. `--url \"https://www.linkedin.com/in/some-profile/\"`.","Check the label in the error — it tells you which key was missing (label defaults to the key name).","If sourcing from an env var, verify it is set and non-empty before invoking: `${MY_URL:?MY_URL is required}`.","Trim the value; whitespace-only strings are rejected."],"exampleFix":"// before\nawait url({ url: process.env.PROFILE_URL || '' });\n// after\nif (!process.env.PROFILE_URL) throw new Error('PROFILE_URL is required');\nawait url({ url: process.env.PROFILE_URL });","handlingStrategy":"validation","validationCode":"if (!args?.url || !String(args.url).trim()) {\n  throw new Error('--url is required');\n}","typeGuard":"function hasArg(args, key) {\n  return typeof args?.[key] === 'string' && args[key].trim().length > 0;\n}","tryCatchPattern":"try {\n  await runCommand(args);\n} catch (e) {\n  if (e instanceof ArgumentError && / is required$/.test(e.message)) {\n    console.error(`Missing required argument: ${e.message.replace(' is required', '')}`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Check required flags before each invocation, especially in CI scripts.","Use shell parameter expansion (:? ) to fail fast on unset env vars.","Trim user-supplied values; whitespace-only counts as missing.","Keep a command usage/help check that lists required flags."],"tags":["argument-validation","missing-argument","cli","linkedin"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}