{"record":{"id":"30b552087bbd895d","repo":"jackwener/OpenCLI","slug":"limit-must-be-an-integer-between-1-and-1000","errorCode":null,"errorMessage":"--limit must be an integer between 1 and 1000","messagePattern":"--limit must be an integer between 1 and 1000","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/twitter/download.js","lineNumber":121,"sourceCode":"    withAuxiliaryUserLabels: true,\n};\n\nconst USER_MEDIA_OPERATION = {\n    queryId: USER_MEDIA_QUERY_ID,\n    features: USER_MEDIA_FEATURES,\n    fieldToggles: USER_MEDIA_FIELD_TOGGLES,\n};\n\nconst USER_BY_SCREEN_NAME_OPERATION = {\n    queryId: USER_BY_SCREEN_NAME_QUERY_ID,\n    features: USER_BY_SCREEN_NAME_FEATURES,\n    fieldToggles: USER_BY_SCREEN_NAME_FIELD_TOGGLES,\n};\n\nfunction requireLimit(value) {\n    const limit = Number(value ?? 10);\n    if (!Number.isInteger(limit) || limit < 1 || limit > 1000) {\n        throw new ArgumentError('--limit must be an integer between 1 and 1000');\n    }\n    return limit;\n}\n\nfunction nextUserMediaFetchCount(limit, downloadedCount) {\n    const remaining = limit - downloadedCount;\n    if (remaining <= 0) return 0;\n    const requested = remaining + 10;\n    if (requested > 100) return 100;\n    return requested;\n}\n\nasync function downloadTwitterMedia(items, options) {\n    const rows = await downloadMedia(items, options);\n    return rows.map((row, index) => {\n        const item = items[index] || {};\n        return {\n            index: row.index,","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/download.js#L103-L139","documentation":"requireLimit in download.js coerces the --limit option (defaulting to 10 via value ?? 10) and throws ArgumentError unless it is an integer from 1 to 1000. This upper bound is much higher than device-follow's 200 because download loops fetch media in batches until the limit is reached.","triggerScenarios":"Calling the download command with --limit as a non-numeric string, a float, 0 or negative, or any integer above 1000. Also triggered by passing null-like placeholders other than actual undefined/null — note value ?? 10 only defaults on undefined/null, so empty string coerces to 0 and fails.","commonSituations":"Scripts exporting empty-string shell variables (--limit \"\"), copying --limit 2000 from batch-download recipes exceeding the cap, or typos like --limit 1o.","solutions":["Pass an integer between 1 and 1000, e.g. --limit 100","Omit --limit to use the default of 10","Fix shell interpolation so empty variables fall back to a number: --limit \"${N:-50}\"","For more than 1000 items, run the command repeatedly with an offset/pagination strategy"],"exampleFix":"// before\ncli twitter download --limit \"\"   # -> Number('') is 0 -> ArgumentError\n// after\ncli twitter download --limit \"${LIMIT:-10}\"","handlingStrategy":"validation","validationCode":"const n = Number(raw ?? 10);\nif (!Number.isInteger(n) || n < 1 || n > 1000) {\n  throw new Error(`--limit must be an integer 1-1000, got: ${JSON.stringify(raw)}`);\n}","typeGuard":"function isValidDownloadLimit(v) {\n  const n = Number(v ?? 10);\n  return Number.isInteger(n) && n >= 1 && n <= 1000;\n}","tryCatchPattern":"try {\n  await cli.twitter.download({ limit: raw });\n} catch (e) {\n  if (e instanceof ArgumentError) {\n    console.error(`Bad --limit '${raw}': use an integer 1-1000`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["Coerce and validate the limit in your wrapper script before invoking","Remember empty string becomes 0 and fails — use ${VAR:-default} in shell","Cap batch recipes at 1000; paginate for more","Avoid non-numeric typos (e.g. --limit 1o) by using a numbers-only flag parser"],"tags":["argument-validation","cli","input-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}