{"record":{"id":"9cc6544fa36ce876","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-9cc654","errorCode":null,"errorMessage":"limit must be a positive integer","messagePattern":"limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/uisdc/news.js","lineNumber":12,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError, getErrorMessage } from '@jackwener/opencli/errors';\n\nconst UISDC_NEWS_URL = 'https://www.uisdc.com/news';\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 50;\n\nfunction normalizeLimit(value) {\n    const raw = value ?? DEFAULT_LIMIT;\n    const limit = Number(raw);\n    if (!Number.isInteger(limit) || limit <= 0) {\n        throw new ArgumentError('limit must be a positive integer', `Example: opencli uisdc news --limit ${DEFAULT_LIMIT}`);\n    }\n    if (limit > MAX_LIMIT) {\n        throw new ArgumentError(`limit must be <= ${MAX_LIMIT}`, `Example: opencli uisdc news --limit ${MAX_LIMIT}`);\n    }\n    return limit;\n}\n\nfunction normalizeText(value) {\n    return String(value ?? '').replace(/\\s+/g, ' ').trim();\n}\n\nfunction buildExtractUisdcNewsJs() {\n    return `\n      (() => {\n        const cards = Array.from(document.querySelectorAll(\n          '.news-list > .news-item:first-child > .item-content > .dubao-items > .dubao-item'\n        ));\n        if (cards.length === 0) {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/uisdc/news.js#L1-L30","documentation":"normalizeLimit in clis/uisdc/news.js validates the user-supplied --limit option and throws ArgumentError 'limit must be a positive integer' when the value is not an integer greater than 0. This guards the API pagination call: a non-numeric, fractional, zero, or negative limit would produce a meaningless or invalid request. The error message includes an example invocation with DEFAULT_LIMIT.","triggerScenarios":"Running `opencli uisdc news --limit abc` (non-numeric), `--limit 0`, `--limit -3`, or `--limit 2.5`; also passing an empty/whitespace value that coerces to NaN. Note limits above 50 throw a different message ('limit must be <= 50').","commonSituations":"Typo in the flag value (`--limt 1o` style fat-fingering); scripting the CLI with a shell variable that is empty or unset; assuming the limit accepts 0 as 'all items'; copying a float from a config file.","solutions":["Pass a positive whole number, e.g. `opencli uisdc news --limit 10`","Use the suggested default from the error message: `opencli uisdc news --limit ${DEFAULT_LIMIT}` (see clis/uisdc/news.js)","Check shell scripts/config for empty or malformed variables feeding --limit (`echo \"${LIMIT_VAR}\"` to inspect)","Remember the ceiling: keep the value between 1 and 50 (MAX_LIMIT)"],"exampleFix":"// before\n$ opencli uisdc news --limit 0\nArgumentError: limit must be a positive integer\n// after\n$ opencli uisdc news --limit 10","handlingStrategy":"validation","validationCode":"function parseLimit(raw, { DEFAULT_LIMIT, MAX_LIMIT } = { DEFAULT_LIMIT: 10, MAX_LIMIT: 50 }) {\n  const limit = Number(raw ?? DEFAULT_LIMIT);\n  if (!Number.isInteger(limit) || limit <= 0) throw new Error('limit must be a positive integer');\n  if (limit > MAX_LIMIT) throw new Error(`limit must be <= ${MAX_LIMIT}`);\n  return limit;\n}","typeGuard":"function isValidLimit(v) {\n  return Number.isInteger(Number(v)) && Number(v) > 0;\n}","tryCatchPattern":"try {\n  await opencli('uisdc', 'news', ['--limit', limitArg]);\n} catch (err) {\n  if (/limit must be/.test(err.message)) {\n    console.error('Use a whole number between 1 and 50, e.g. --limit 10');\n  } else { throw err; }\n}","preventionTips":["Always pass explicit positive integers to --limit; avoid shell variables that may be empty","Remember the range is 1..50 (MAX_LIMIT = 50); 0 is not 'unlimited'","Quote and validate interpolated values in scripts before invoking the CLI","Coerce strings to integers (parseInt with radix 10) before passing them as flags"],"tags":["argument-validation","cli","input-validation","uisdc"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}