sansan0/TrendRadar · error · InvalidParameterError
limit 必须大于0
Error message
limit 必须大于0
What it means
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.
Source
Thrown at mcp_server/utils/validators.py:283
Returns:
验证后的限制值
Raises:
InvalidParameterError: 参数无效
"""
if limit is None:
return default
# 支持字符串形式的整数(某些 MCP 客户端会将数字序列化为字符串)
if isinstance(limit, str):
limit = _parse_string_to_int(limit, "limit")
if not isinstance(limit, int):
raise InvalidParameterError("limit 参数必须是整数类型")
if limit <= 0:
raise InvalidParameterError("limit 必须大于0")
if limit > max_limit:
raise InvalidParameterError(
f"limit 不能超过 {max_limit}",
suggestion=f"请使用分页或降低limit值"
)
return limit
def validate_date(date_str: str) -> datetime:
"""
验证日期格式
Args:
date_str: 日期字符串 (YYYY-MM-DD)
Returns:View on GitHub (pinned to 8ee26026ba)
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
Example fix
// before
{"limit": 0}
// after
{"limit": 20} Defensive patterns
Strategy: validation
Validate before calling
const limit = Math.max(1, computedLimit | 0); // clamp to >=1
Try / catch
try { call({ limit }); }
catch (e) {
if (/limit 必须大于0/.test(e.message)) call({ limit: 20 });
else throw e;
} Prevention
- 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)
When it happens
Trigger: 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).
Common situations: 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.
Related errors
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/c9907384059d555c.
Report an issue: GitHub.