{"record":{"id":"ae3ecb4cd82a9b26","repo":"jackwener/OpenCLI","slug":"homebrew-label-is-required-e-g-wget-gcc-1","errorCode":null,"errorMessage":"homebrew ${label} is required (e.g. \"wget\", \"gcc@13\", \"firefox\")","messagePattern":"homebrew (.+?) is required \\(e\\.g\\. \"wget\", \"gcc@13\", \"firefox\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/homebrew/utils.js","lineNumber":37,"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(`homebrew ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`homebrew ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireToken(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(`homebrew ${label} is required (e.g. \"wget\", \"gcc@13\", \"firefox\")`);\n    }\n    if (s.length > 100 || !TOKEN.test(s)) {\n        throw new ArgumentError(\n            `homebrew ${label} \"${value}\" is not a valid token`,\n            'Use letters / digits / \"_-.+@\", starting with a letter or digit (max 100 chars).',\n        );\n    }\n    return s;\n}\n\nexport function requireOneOf(value, allowed, label) {\n    const s = String(value ?? '').trim().toLowerCase();\n    if (!s) throw new ArgumentError(`homebrew ${label} is required`);\n    if (!allowed.includes(s)) {\n        throw new ArgumentError(\n            `homebrew ${label} \"${value}\" is not supported`,\n            `Allowed: ${allowed.join(', ')}.`,\n        );","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/homebrew/utils.js#L19-L55","documentation":"requireToken throws ArgumentError('homebrew <label> is required (e.g. \"wget\", \"gcc@13\", \"firefox\")') when the token argument (formula or cask name) is missing or empty after trimming. It is the friendly 'you forgot the argument' guard for token-taking commands like info/search.","triggerScenarios":"Running a command without its token argument (e.g. `homebrew info` with no name), or passing an empty/whitespace string or null/undefined programmatically.","commonSituations":"Scripts calling the API with an unset variable, CLI users omitting the positional argument, quoting errors that swallow the value.","solutions":["Supply a formula or cask token, e.g. `homebrew info wget`","Check that the variable feeding the token is set and non-empty","Validate non-empty input before invoking the command","Catch ArgumentError and show the usage hint included in the error"],"exampleFix":"// before\nawait homebrewInfo(process.argv[3]);\n// after\nconst token = (process.argv[3] ?? '').trim();\nif (!token) {\n  console.error('Usage: homebrew info <formula|cask>');\n  process.exit(2);\n}\nawait homebrewInfo(token);","handlingStrategy":"validation","validationCode":"const token = String(rawToken ?? '').trim();\nif (!token) {\n  console.error('Usage: homebrew <command> <formula|cask>  e.g. homebrew info wget');\n  process.exit(2);\n}","typeGuard":"function isProvidedToken(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await homebrewInfo(rawToken);\n} catch (err) {\n  if (err instanceof ArgumentError && /is required/.test(err.message)) {\n    console.error(err.message + '\\n' + (err.hint ?? ''));\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Require the positional argument in your CLI wrapper before invoking","Use ${TOKEN:?unset} style guards in shell scripts","Show usage text when arg count is below the minimum","Trim inputs to avoid whitespace-only values slipping through"],"tags":["validation","argument-error","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}