{"record":{"id":"c9907384059d555c","repo":"sansan0/TrendRadar","slug":"limit-0","errorCode":null,"errorMessage":"limit 必须大于0","messagePattern":"limit 必须大于0","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":283,"sourceCode":"\n    Returns:\n        验证后的限制值\n\n    Raises:\n        InvalidParameterError: 参数无效\n    \"\"\"\n    if limit is None:\n        return default\n\n    # 支持字符串形式的整数（某些 MCP 客户端会将数字序列化为字符串）\n    if isinstance(limit, str):\n        limit = _parse_string_to_int(limit, \"limit\")\n\n    if not isinstance(limit, int):\n        raise InvalidParameterError(\"limit 参数必须是整数类型\")\n\n    if limit <= 0:\n        raise InvalidParameterError(\"limit 必须大于0\")\n\n    if limit > max_limit:\n        raise InvalidParameterError(\n            f\"limit 不能超过 {max_limit}\",\n            suggestion=f\"请使用分页或降低limit值\"\n        )\n\n    return limit\n\n\ndef validate_date(date_str: str) -> datetime:\n    \"\"\"\n    验证日期格式\n\n    Args:\n        date_str: 日期字符串 (YYYY-MM-DD)\n\n    Returns:","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L265-L301","documentation":"Raised by validate_limit when limit <= 0 after type checks. Zero and negatives are rejected because a query returning 'at most 0 items' is meaningless. String inputs were already coerced, so \"0\" and \"-5\" also land here.","triggerScenarios":"Explicitly passing limit: 0 (often done to mean 'no limit'), limit: -1 as an 'all results' sentinel, or a computed value that underflowed to 0 (e.g. an empty array's length).","commonSituations":"API conventions where 0 or -1 means unlimited (this API rejects that); LLMs emitting 0 for 'default'; pagination math producing 0 when a count is empty; defaults from uninitialised counters.","solutions":["Omit limit or pass null to get the default (20) instead of 0","Pass a positive integer; for 'as much as possible' use a large value within max_limit (default 1000)","Fix the caller's computation so it cannot produce 0 (e.g. Math.max(1, computed))","If you truly need unlimited, implement pagination with offset/cursor rather than abusing limit"],"exampleFix":"// before\n{\"limit\": 0}\n// after\n{\"limit\": 20}","handlingStrategy":"validation","validationCode":"const limit = Math.max(1, computedLimit | 0); // clamp to >=1","typeGuard":null,"tryCatchPattern":"try { call({ limit }); }\ncatch (e) {\n  if (/limit 必须大于0/.test(e.message)) call({ limit: 20 });\n  else throw e;\n}","preventionTips":["Map 'unlimited' intent to the max_limit value or pagination, not 0/-1","Omit limit when you want the default","Guard computed limits with Math.max(1, x)"],"tags":["validation","limit","pagination"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}