sansan0/TrendRadar · error · InvalidParameterError
不允许查询未来日期: {', '.join(future_dates)}(当前日期: {today.strftime('
Error message
不允许查询未来日期: {', '.join(future_dates)}(当前日期: {today.strftime('%Y-%m-%d')}) What it means
Raised when start or end is strictly after today (server-local date). The message lists the future date(s) and today's date; the suggestion attempts to show the actual available data range by consulting DataService.get_available_date_range() (falling back to '未知(请检查 output 目录)' on failure). This guards both against typos and against querying dates with no data.
Source
Thrown at mcp_server/utils/validators.py:474
try:
from ..services.data_service import DataService
data_service = DataService()
earliest, latest = data_service.get_available_date_range()
if earliest and latest:
available_range = f"{earliest.strftime('%Y-%m-%d')} 至 {latest.strftime('%Y-%m-%d')}"
else:
available_range = "无可用数据"
except Exception:
available_range = "未知(请检查 output 目录)"
future_dates = []
if start_date.date() > today:
future_dates.append(start_str)
if end_date.date() > today and end_str != start_str:
future_dates.append(end_str)
raise InvalidParameterError(
f"不允许查询未来日期: {', '.join(future_dates)}(当前日期: {today.strftime('%Y-%m-%d')})",
suggestion=f"当前可用数据范围: {available_range}"
)
return (start_date, end_date)
def validate_keyword(keyword: str) -> str:
"""
验证关键词
Args:
keyword: 搜索关键词
Returns:
处理后的关键词
Raises:View on GitHub (pinned to 8ee26026ba)
Solutions
- Clamp both bounds to today client-side before sending
- Fix year typos (2030/2205 style errors are almost always typos)
- If client/server timezones differ, use the server's date notion (or clamp with margin) — 'today' is server-local datetime.now()
- Read the suggestion's available range and query within it
Example fix
// before
{"date_range": {"start": "2025-10-01", "end": "2030-10-11"}}
// after
const today = new Date().toISOString().slice(0, 10);
{"date_range": {"start": "2025-10-01", "end": today}} Defensive patterns
Strategy: validation
Validate before calling
const today = new Date().toISOString().slice(0, 10); if (dr.end > today) dr.end = today; if (dr.start > today) dr.start = today; if (dr.start > dr.end) dr.start = dr.end;
Type guard
const isNotFuture = (s: string): boolean => s <= new Date().toISOString().slice(0, 10);
Try / catch
try { call({ date_range: dr }); }
catch (e) {
const m = e.message.match(/当前日期: (\d{4}-\d{2}-\d{2})/);
if (m) { dr.end = m[1]; if (dr.start > m[1]) dr.start = m[1]; call({ date_range: dr }); }
else throw e;
} Prevention
- Clamp both bounds to today before every call
- Use the server's reported date from a failed attempt to re-sync client clock assumptions
- Watch timezone skew: server 'today' is server-local, not UTC
When it happens
Trigger: Sending {"start": "2030-01-01", "end": "2030-12-31"}; a typo year like 2205-10-11; client clock skew if the client machine is ahead of the server; year-first transposition 2025→2052. start == today and end == today are fine; only strictly-future dates trip it.
Common situations: Forecast/planning queries against a historical-data-only service; LLM hallucinating future years; client/server timezone mismatch around midnight UTC vs local; typo'd years.
Related errors
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/4ba28be178f496f1.
Report an issue: GitHub.