{"record":{"id":"9c0cdb0e115644f1","repo":"jackwener/OpenCLI","slug":"weibo-favorites-name-must-be-a-positive-integer","errorCode":null,"errorMessage":"weibo favorites ${name} must be a positive integer","messagePattern":"weibo favorites (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/weibo/favorites.js","lineNumber":12,"sourceCode":"import { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { getSelfUid, requireArrayEvaluateResult, unwrapEvaluateResult } from './utils.js';\n\nconst DEFAULT_LIMIT = 20;\nconst MAX_LIMIT = 50;\n\nfunction parsePositiveInt(value, name, defaultValue) {\n  const raw = value ?? defaultValue;\n  const number = Number(raw);\n  if (!Number.isInteger(number) || number <= 0) {\n    throw new ArgumentError(`weibo favorites ${name} must be a positive integer`);\n  }\n  if (number > MAX_LIMIT) {\n    throw new ArgumentError(`weibo favorites ${name} must be <= ${MAX_LIMIT}`);\n  }\n  return number;\n}\n\nfunction parseFavoriteCard(card, favUrl) {\n  const raw = String(card?.text ?? '');\n  const lines = raw.split('\\n');\n\n  let author = '';\n  let time = '';\n  let source = '';\n  let content = '';\n  let likes = '0';\n  let comments = '0';\n  let reposts = '0';","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/favorites.js#L1-L30","documentation":"clis/weibo/favorites.js:12 — parsePositiveInt throws ArgumentError(`weibo favorites ${name} must be a positive integer`) when a numeric option (e.g. limit, called via the limit option handler) is not an integer or is <= 0. Defaults apply only when the value is nullish; any provided value must be a strictly positive integer. MAX_LIMIT is 50.","triggerScenarios":"Calling `weibo favorites` with limit=0, a negative number, a non-integer like 2.5, or a non-numeric string such as limit=\"abc\" or \"\" (Number('') is 0).","commonSituations":"Users passing 0 expecting 'unlimited'; config/env strings like '20 ' or 'twenty' not being pre-parsed; scripts interpolating empty variables into limit; fractional values from dividing counts.","solutions":["Pass a positive integer, e.g. limit: 20 (omit the option entirely to use the default)","Coerce and validate user/config input before the call: Number(value) and Number.isInteger check","Trim numeric strings; empty string is not a valid value — drop it so the default applies","Remember the hard cap is 50; larger values need the <=50 error (see next entry)"],"exampleFix":"// before\nawait cli.run('weibo favorites', { limit: '20 ' }); // ArgumentError\n// after\nconst n = Number(String(cfg.limit ?? '').trim());\nawait cli.run('weibo favorites', { limit: Number.isInteger(n) && n > 0 ? n : undefined });","handlingStrategy":"validation","validationCode":"function toPositiveInt(v, fallback = 20) {\n  if (v == null || v === '') return fallback;\n  const n = Number(v);\n  return Number.isInteger(n) && n > 0 ? n : fallback;\n}","typeGuard":"function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v > 0; }","tryCatchPattern":"try {\n  await cli.run('weibo favorites', { limit });\n} catch (e) {\n  if (e instanceof Error && /must be a positive integer/.test(e.message)) {\n    console.error(`limit must be a positive integer, got: ${JSON.stringify(limit)}`);\n  }\n  throw e;\n}","preventionTips":["Coerce config/env strings with Number() and trim whitespace before passing","Drop empty values so the CLI default (20) applies","Reject 0 early — the CLI treats it as invalid, not 'unlimited'","Unit-test option parsing in scripts that build CLI args dynamically"],"tags":["validation","argument-error","weibo","parameters"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}