{"record":{"id":"736f33e158bda31d","repo":"jackwener/OpenCLI","slug":"homebrew-label-value-is-not-a-valid-token","errorCode":null,"errorMessage":"homebrew ${label} \"${value}\" is not a valid token","messagePattern":"homebrew (.+?) \"(.+?)\" is not a valid token","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/homebrew/utils.js","lineNumber":40,"sourceCode":"export 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        );\n    }\n    return s;\n}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/homebrew/utils.js#L22-L58","documentation":"requireToken throws ArgumentError('homebrew <label> \"<value>\" is not a valid token') (with a hint about allowed characters) when the token is non-empty but fails Homebrew's token charset rules: it must match /^[A-Za-z0-9][A-Za-z0-9._+@-]*$/ and be at most 100 characters.","triggerScenarios":"Passing tokens with spaces, slashes, shell globs, or URL-ish input (e.g. 'node.js/' or 'my formula'), tokens starting with a symbol like '@', or >100-char garbage from a bad variable.","commonSituations":"Users pasting full URLs (https://formulae.brew.sh/formula/wget) instead of the token, copying names with surrounding punctuation, or quoting mistakes splitting 'gcc@13' in shells that expand '@'.","solutions":["Use the bare token only — e.g. `wget`, `gcc@13`, `firefox` — no URLs or paths","Strip invalid characters/spaces and retry with a valid token","If passing from a shell, quote the token ('gcc@13') to avoid expansion","Validate against /^[A-Za-z0-9][A-Za-z0-9._+@-]*$/ before calling"],"exampleFix":"// before\nawait homebrewInfo('https://formulae.brew.sh/formula/wget');\n// after\nconst raw = 'https://formulae.brew.sh/formula/wget';\nconst token = raw.split('/').filter(Boolean).pop();\nawait homebrewInfo(token); // 'wget'","handlingStrategy":"validation","validationCode":"const TOKEN_RE = /^[A-Za-z0-9][A-Za-z0-9._+@-]*$/;\nconst token = String(raw ?? '').trim();\nif (!TOKEN_RE.test(token) || token.length > 100) {\n  throw new Error(`\"${raw}\" is not a valid Homebrew token (letters/digits/\"_-.+@\", max 100 chars)`);\n}","typeGuard":"function isValidBrewToken(v) {\n  return typeof v === 'string' && v.length <= 100 &&\n    /^[A-Za-z0-9][A-Za-z0-9._+@-]*$/.test(v);\n}","tryCatchPattern":"try {\n  await homebrewInfo(raw);\n} catch (err) {\n  if (err instanceof ArgumentError && /not a valid token/.test(err.message)) {\n    console.error(`${err.message}\\n${err.hint ?? ''}`);\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Pass bare tokens (wget, gcc@13), never URLs or paths","Quote tokens in shells so @ is not expanded","Normalize input: strip protocol/host if users paste URLs","Pre-validate against the token regex before calling the command"],"tags":["validation","argument-error","input-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}