{"record":{"id":"d0f350aa2d17a7b6","repo":"jackwener/OpenCLI","slug":"packagist-package-name-is-required-e-g-symfony","errorCode":null,"errorMessage":"packagist package name is required (e.g. \"symfony/console\", \"monolog/monolog\")","messagePattern":"packagist package name is required \\(e\\.g\\. \"symfony/console\", \"monolog/monolog\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/packagist/utils.js","lineNumber":35,"sourceCode":"    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(`packagist ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`packagist ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requirePackageName(value) {\n    const raw = String(value ?? '').trim().toLowerCase();\n    if (!raw) {\n        throw new ArgumentError('packagist package name is required (e.g. \"symfony/console\", \"monolog/monolog\")');\n    }\n    const slash = raw.indexOf('/');\n    if (slash <= 0 || slash === raw.length - 1) {\n        throw new ArgumentError(\n            `packagist package \"${value}\" must be \"<vendor>/<package>\"`,\n            'Both segments are required (Composer convention).',\n        );\n    }\n    const vendor = raw.slice(0, slash);\n    const pkg = raw.slice(slash + 1);\n    if (vendor.length > 100 || pkg.length > 100 || !SEGMENT.test(vendor) || !SEGMENT.test(pkg)) {\n        throw new ArgumentError(\n            `packagist package \"${value}\" is not a valid Composer name`,\n            'Use lowercase letters / digits / \"_-.\", segments separated by single \"_-.\" chars (max 100 chars each).',\n        );\n    }\n    return { vendor, package: pkg, full: `${vendor}/${pkg}` };\n}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/packagist/utils.js#L17-L53","documentation":"requirePackageName throws this ArgumentError when, after trimming and lowercasing, the supplied package name is empty (or contains no '/' at a valid position — see sibling errors). Composer packages are always `<vendor>/<package>`, and this adapter refuses to build a Packagist URL without one. The message includes example names.","triggerScenarios":"Calling full (which calls requirePackageName) with '', '   ', null, or undefined as the package name, e.g. `packagist full ''`.","commonSituations":"Shell variable holding the package name is unset/empty ($PKG empty); user forgot the positional argument; JSON/config field missing; template expansion produced an empty string.","solutions":["Pass a full Composer name like \"symfony/console\" or \"monolog/monolog\".","Verify the shell/config variable feeding the argument is actually set.","Catch ArgumentError and print usage showing the vendor/package format.","Prompt the user for the package name if it was not supplied."],"exampleFix":"// before\nconst name = process.env.PKG ?? '';\nawait full(name); // empty -> throws\n\n// after\nconst name = process.env.PKG;\nif (!name) throw new Error('Set PKG, e.g. PKG=symfony/console');\nawait full(name);","handlingStrategy":"validation","validationCode":"function looksLikeComposerName(v) {\n  return typeof v === 'string' && v.trim().length > 0 && v.includes('/');\n}\nif (!looksLikeComposerName(name)) {\n  throw new Error('expected <vendor>/<package>, e.g. symfony/console');\n}","typeGuard":"const isFilledString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await full(name);\n} catch (e) {\n  if (e instanceof ArgumentError && /package name is required/.test(e.message)) {\n    console.error('Usage: packagist full <vendor>/<package>');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Check shell variables with ${PKG:?not set} before invoking.","Make the package argument required in your argument parser.","Show an example (symfony/console) in usage text.","Fail fast at script start when required inputs are blank."],"tags":["argument-validation","missing-argument","composer","packagist"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}