{"record":{"id":"7be6ba0cbfa76ac4","repo":"jackwener/OpenCLI","slug":"npm-package-name-value-is-too-long-max-214-c","errorCode":null,"errorMessage":"npm package name \"${value}\" is too long (max 214 chars)","messagePattern":"npm package name \"(.+?)\" is too long \\(max 214 chars\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/npm/utils.js","lineNumber":22,"sourceCode":"\nexport const NPM_REGISTRY = 'https://registry.npmjs.org';\nexport const NPM_API = 'https://api.npmjs.org';\nconst UA = 'opencli-npm-adapter (+https://github.com/jackwener/opencli)';\n\n// npm package names: 1-214 chars, lowercase letters/numbers/-._ , scoped form `@scope/name`.\nconst PKG_NAME = /^(?:@[a-z0-9][a-z0-9._-]*\\/)?[a-z0-9][a-z0-9._-]*$/i;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`npm ${label} cannot be empty`);\n    return s;\n}\n\nexport function requirePackageName(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('npm package name is required (e.g. \"react\", \"@vercel/og\")');\n    if (s.length > 214) {\n        throw new ArgumentError(`npm package name \"${value}\" is too long (max 214 chars)`);\n    }\n    if (!PKG_NAME.test(s)) {\n        throw new ArgumentError(\n            `npm package name \"${value}\" is not a valid registry name`,\n            'Names are 1–214 chars of lowercase a-z / 0-9 / \"-._\" (scoped form: \"@scope/name\").',\n        );\n    }\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`npm ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`npm ${label} must be <= ${maxValue}`);","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/npm/utils.js#L4-L40","documentation":"requirePackageName enforces the npm registry limit of 214 characters per package name and throws ArgumentError when the trimmed name exceeds it. npm itself rejects names longer than 214 chars, so the library short-circuits before hitting the network.","triggerScenarios":"Passing a name longer than 214 characters — e.g. a file path or URL pasted as the package name, an accidentally repeated string, or concatenated scope+name strings built programmatically.","commonSituations":"Pasting a full URL or node_modules path into --name; concatenating many packages into one argument; generated names in tooling that skipped a truncation step.","solutions":["Supply just the package name, not a path or URL — `react`, not `./node_modules/react` or `https://npmjs.com/package/react`.","Trim/split input; if handling a list of packages, pass them one at a time.","If a name is legitimately near the limit, verify it with `npm view <name>` first.","Catch ArgumentError to inform the user their input is too long."],"exampleFix":"// before\nawait npmDownloads({ name: process.argv[2] }); // argv[2] was a 300-char path\n// after\nlet name = process.argv[2];\nif (name.includes('/')) name = name.split('/').pop(); // strip paths/URLs\nif (name.length > 214) throw new Error('Not a package name');\nawait npmDownloads({ name });","handlingStrategy":"validation","validationCode":"function isValidNameLength(v) {\n  return typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= 214;\n}\nif (!isValidNameLength(args.name)) throw new Error('Provide an npm package name (max 214 chars), not a path/URL');","typeGuard":"function isValidNameLength(v) {\n  return typeof v === 'string' && v.trim().length >= 1 && v.trim().length <= 214;\n}","tryCatchPattern":"try {\n  return await npmPackage({ name });\n} catch (e) {\n  if (e.name === 'ArgumentError' && /too long/.test(e.message)) {\n    console.error('That does not look like a package name (paths/URLs are not accepted).');\n    return null;\n  }\n  throw e;\n}","preventionTips":["Never pass file paths or URLs where a package name is expected.","Strip protocol/path prefixes from user input before passing the name.","Enforce the 214-char limit in your own input layer with a clear message.","Sanitize programmatically-built names that concatenate strings."],"tags":["validation","argument-error","npm","package-name-length"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}