{"record":{"id":"8e41c0d4c2bc3b13","repo":"jackwener/OpenCLI","slug":"limit-must-be-a-positive-integer-8e41c0","errorCode":null,"errorMessage":"--limit must be a positive integer","messagePattern":"--limit must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/jike/utils.js","lineNumber":40,"sourceCode":"    return { ok: true, user_id: String(u.id), screen_name: String(u.screenName || ''), username: String(u.username || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nexport async function requireJikeIdentity(page) {\n  const probe = await page.evaluate(JIKE_IDENTITY_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('web.okjike.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Jike users/profile`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Jike identity probe failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Jike identity probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, screen_name: probe.screen_name, username: probe.username };\n}\n\nexport function normalizeJikeLimit(raw, defaultValue = 20) {\n  const limit = raw ?? defaultValue;\n  if (!Number.isInteger(limit) || limit < 1) {\n    throw new ArgumentError('--limit must be a positive integer');\n  }\n  return limit;\n}\n\nexport async function postJikeApi(page, path, requestBody, label) {\n  const url = `https://api.ruguoapp.com${path}`;\n  const outcome = await page.evaluate(`(async () => {\n    const token = localStorage.getItem('JK_ACCESS_TOKEN') || '';\n    const deviceId = localStorage.getItem('JK_DEVICE_ID') || '';\n    if (!token) return { kind: 'auth', detail: 'Jike access token is missing' };\n    const headers = {\n      'content-type': 'application/json',\n      'x-jike-access-token': token,\n      platform: 'web',\n    };\n    if (deviceId) headers['x-jike-device-id'] = deviceId;\n    try {\n      const response = await fetch(${JSON.stringify(url)}, {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jike/utils.js#L22-L58","documentation":"ArgumentError thrown by normalizeJikeLimit when the --limit value (after nullish-coalescing with the default) is not an integer or is less than 1. The library validates user input early so downstream slicing/pagination receives a safe positive integer.","triggerScenarios":"Calling a Jike command with --limit 0, a negative number, a non-numeric string, or a float like 2.5 that reaches the function unconverted.","commonSituations":"Typing --limit 0 expecting unlimited results; passing a decimal; shell quoting issues passing an empty or malformed string that bypasses the default; scripting the CLI with variables that are unset/invalid.","solutions":["Pass a positive integer, e.g. --limit 20","Omit --limit entirely to use the default (20)","Check for shell quoting/variable-expansion issues producing a bad value","Validate the value in any wrapper script before invoking the CLI"],"exampleFix":"// before\njike user --limit 0\n// after\njike user --limit 20   # or omit --limit for default","handlingStrategy":"validation","validationCode":"function isValidLimit(v) { return Number.isInteger(v) && v >= 1; }\nif (!isValidLimit(opts.limit)) throw new Error('--limit must be a positive integer');","typeGuard":"function isPositiveInt(v) { return typeof v === 'number' && Number.isInteger(v) && v >= 1; }","tryCatchPattern":null,"preventionTips":["Always pass whole numbers >= 1 for --limit","Omit --limit to use the default (20)","Sanitize variables in wrapper scripts before invoking the CLI","Quote shell arguments to avoid empty/malformed values"],"tags":["argument-validation","cli","input"],"backgroundTag":"invalid-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}