{"record":{"id":"7f2ad460bf247615","repo":"jackwener/OpenCLI","slug":"maven-label-must-be-a-positive-integer","errorCode":null,"errorMessage":"maven ${label} must be a positive integer","messagePattern":"maven (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/maven/utils.js","lineNumber":26,"sourceCode":"export const MAVEN_BASE = 'https://search.maven.org/solrsearch/select';\nexport const MAVEN_REPO_BASE = 'https://repo1.maven.org/maven2';\nconst UA = 'opencli-maven-adapter (+https://github.com/jackwener/opencli)';\n\n// Maven groupId / artifactId tokens — Java-package-ish (letters / digits /\n// `_-.`), 1-200 chars; reverse-DNS dots are allowed in groupId.\nconst COORD_TOKEN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`maven ${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(`maven ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`maven ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\n/**\n * Parse a Maven coordinate `groupId:artifactId[:version]` into segments.\n * groupId / artifactId are required; version is optional.\n */\nexport function requireCoord(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) {\n        throw new ArgumentError('maven coordinate is required (e.g. \"com.fasterxml.jackson.core:jackson-databind\")');\n    }\n    const parts = raw.split(':');\n    if (parts.length < 2 || parts.length > 3) {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/maven/utils.js#L8-L44","documentation":"`requireBoundedInt` validates numeric arguments (defaulting to `defaultValue` when omitted) and throws ArgumentError with `maven ${label} must be a positive integer` when the value is not an integer or is <= 0. For the `limit` argument this means you passed something like 0, -5, NaN, a non-numeric string, or a fractional number as the result limit.","triggerScenarios":"Calling an operation with `limit: 0`, `limit: -1`, `limit: 'ten'`, `limit: 2.5`, or `limit: NaN` — anything where Number coercion does not produce a positive integer. Omitting limit is fine (defaults to 30).","commonSituations":"A CLI flag parsed as string ('--limit 0' becomes the string '0', still 0 -> throws); a config value of null explicitly overriding the default; user input not sanitized; JS NaN from a failed parseInt; passing a boolean or object by mistake.","solutions":["Pass a positive integer for the argument (e.g. limit: 20) or omit it to use the default (30)","Coerce and validate user input before the call: Number.isInteger(Number(value)) && Number(value) > 0","Check whether a falsy value (0, null) is accidentally overriding the library's default via `value ?? defaultValue` — null/undefined are fine, 0 is not","Note the upper bound too: the value must also be <= 200 for limit"],"exampleFix":"// before\nawait mavenSearch({ query: 'jackson', limit: 0 });\n// after\nawait mavenSearch({ query: 'jackson', limit: Math.min(200, Math.max(1, parseInt(userLimit, 10) || 30)) });","handlingStrategy":"validation","validationCode":"function parseLimit(v, dflt = 30, max = 200) {\n  if (v == null) return dflt;\n  const n = typeof v === 'number' ? v : Number(v);\n  if (!Number.isInteger(n) || n <= 0) throw new Error('limit must be a positive integer');\n  return n;\n}","typeGuard":"function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  const docs = await mavenSearch({ query, limit });\n} catch (err) {\n  if (err instanceof ArgumentError && /positive integer/.test(err.message)) {\n    console.error('limit must be a positive integer, e.g. --limit 30');\n    return;\n  }\n  throw err;\n}","preventionTips":["Omit the limit argument to use the default (30) unless you need otherwise","Coerce CLI strings with parseInt and validate with Number.isInteger","Guard against 0 and null overriding defaults — null/undefined fall back, 0 throws","Sanitize user input before passing numeric options"],"tags":["argument-error","maven","integer-validation","input-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}