{"record":{"id":"f7a7cb5c2517fd3b","repo":"jackwener/OpenCLI","slug":"packagist-label-cannot-be-empty","errorCode":null,"errorMessage":"packagist ${label} cannot be empty","messagePattern":"packagist (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/packagist/utils.js","lineNumber":16,"sourceCode":"// Shared helpers for the Packagist (PHP / Composer) adapters.\n//\n// Hits the public, unauthenticated `packagist.org` JSON endpoints. Composer's\n// canonical package registry. Package names are `<vendor>/<package>`,\n// lowercase letters / digits / `_-.`, with each segment 1-100 chars.\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const PACKAGIST_BASE = 'https://packagist.org';\nconst UA = 'opencli-packagist-adapter (+https://github.com/jackwener/opencli)';\n\n// Each segment of a Composer package name (`vendor` and `package`).\nconst SEGMENT = /^[a-z0-9]([_.-]?[a-z0-9]+)*$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`packagist ${label} cannot be empty`);\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(`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) {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/packagist/utils.js#L1-L34","documentation":"The Packagist adapter's requireString helper normalizes its input with String(value ?? '').trim() and throws this ArgumentError when the result is empty. It is a guard ensuring required string arguments (labeled via `label`) are non-empty before any API work happens. Throwing early keeps callers from sending meaningless requests to packagist.org.","triggerScenarios":"Calling query() (via requireString) with an empty string, whitespace-only string, null, or undefined for a required labeled parameter, e.g. requireString(searchParams.get('q'), 'query') where the query parameter is missing.","commonSituations":"CLI invoked without a required positional argument; an env var or config key holding an empty string; upstream code passing null/undefined instead of a value; user pressing enter on an empty prompt.","solutions":["Provide a non-empty value for the labeled argument before calling query().","If the value comes from env/config, check it is set and non-blank (not just truthy after coercion).","Catch ArgumentError in your entry point and print usage help prompting for the missing value.","Trim user input and re-prompt if the trimmed result is empty."],"exampleFix":"// before\nawait query(opts.q, { limit: 10 }); // opts.q may be undefined\n\n// after\nif (!opts.q || !opts.q.trim()) {\n  throw new Error('Usage: packagist query <term>');\n}\nawait query(opts.q.trim(), { limit: 10 });","handlingStrategy":"validation","validationCode":"function hasQuery(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}\nif (!hasQuery(term)) throw new Error('query term required');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  await query(term);\n} catch (e) {\n  if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {\n    console.error('A query term is required.');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Validate CLI args with a parser (yargs/commander) that enforces required arguments.","Trim all user input and treat whitespace-only as missing.","Check env/config values at startup, not at call time.","Require arguments explicitly in scripts with a usage() guard."],"tags":["argument-validation","empty-input","packagist","cli"],"backgroundTag":"empty-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}