sansan0/TrendRadar · error · DataNotFoundError

DATA_NOT_FOUND

DATA_NOT_FOUND

Error message

未找到包含关键词 '{keyword}' 的新闻

What it means

Raised by Scheduler._validate_hhmm after the HH:MM shape check passes but the numeric values are out of range: hour must be 0-23 and minute 0-59. The regex only enforces two digits, so '25:70' is shape-valid but semantically invalid, and this second ValueError fires. It indicates a well-formatted but impossible clock time in scheduler config.

Source

Thrown at mcp_server/services/data_service.py:273

                                "ranks": info["ranks"],
                                "count": len(info["ranks"]),
                                "avg_rank": round(avg_rank, 2),
                                "url": info.get("url", ""),
                                "mobileUrl": info.get("mobileUrl", ""),
                                "date": current_date.strftime("%Y-%m-%d")
                            })

                            platform_distribution[platform_id] += 1

            except DataNotFoundError:
                # 该日期没有数据,继续下一天
                pass

            # 下一天
            current_date += timedelta(days=1)

        if not results:
            raise DataNotFoundError(
                f"未找到包含关键词 '{keyword}' 的新闻",
                suggestion="请尝试其他关键词或扩大日期范围"
            )

        # 计算统计信息
        total_ranks = []
        for item in results:
            total_ranks.extend(item["ranks"])

        avg_rank = sum(total_ranks) / len(total_ranks) if total_ranks else 0

        # 限制返回数量(如果指定)
        total_found = len(results)
        if limit is not None and limit > 0:
            results = results[:limit]

        return {
            "results": results,

View on GitHub (pinned to 8ee26026ba)

Solutions

  1. Correct the value: hours 0-23, minutes 0-59. Replace '24:00' with '00:00'.
  2. For windows crossing midnight, split into two windows or use the library's supported overnight representation instead of inflating the hour (e.g. 22:00-02:00, not 22:00-26:00).
  3. If computing times programmatically, normalize with divmod: h, m = divmod(total_minutes, 60); h %= 24 before formatting.
  4. Validate config with a stricter regex '^([01]\d|2[0-3]):[0-5]\d$' upfront to catch range errors at load time.

Example fix

# before
window = {"start": "22:00", "end": "24:30"}

# after
window = {"start": "22:00", "end": "00:30"}  # crosses midnight

# normalize computed times
total = 25 * 60 + 70
h, m = divmod(total, 60)
h %= 60  # wrap hours into 0-23 after adding minutes
value = f"{h % 24:02d}:{m:02d}"
Defensive patterns

Strategy: validation

Validate before calling

def is_valid_hhmm(value: str) -> bool:
    """Shape AND range: HH 00-23, MM 00-59."""
    if not re.match(r"^\d{2}:\d{2}$", value):
        return False
    h, m = int(value[:2]), int(value[3:])
    return 0 <= h <= 23 and 0 <= m <= 59

assert all(is_valid_hhmm(t) for t in config["quiet_hours"].values())

Type guard

def is_valid_hhmm(value: str) -> bool:
    if not isinstance(value, str) or not re.match(r"^\d{2}:\d{2}$", value):
        return False
    h, m = int(value[:2]), int(value[3:])
    return 0 <= h <= 23 and 0 <= m <= 59

Prevention

When it happens

Trigger: Calling _validate_hhmm (directly or via scheduler config validation) with values such as '24:00' (use '00:00' for midnight), '25:30' (hour > 23), '09:60' or '12:99' (minute > 59). Arithmetic on times that carries past bounds, e.g. computing end = start + duration and producing '23:90', also triggers it.

Common situations: Config authored with '24:00' intending end-of-day; wrap-around windows like 22:00-26:00 written literally instead of 22:00-02:00; time arithmetic in generating scripts that does not modulo the hour/minute; copy-paste of military/local 24h+ conventions.

Related errors


AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15). Data as JSON: /api/errors/ac8fcca94fc55458. Report an issue: GitHub.