sansan0/TrendRadar · error · InvalidParameterError
INVALID_PARAMETER
INVALID_PARAMETER
Error message
无效的洞察类型: {insight_type} What it means
The generic Webhook send function in senders.py requires a caller-supplied content-splitting function (split_content_func) because it must batch long messages to the webhook's size limit. It refuses to run with None, raising ValueError immediately, rather than silently sending a truncated or oversized payload. This is a programming/parameter error at the call site, not an environmental issue.
Source
Thrown at mcp_server/tools/analytics.py:143
- "platform_activity": 平台活跃度统计(统计各平台发布频率和活跃时间)
- "keyword_cooccur": 关键词共现分析(分析关键词同时出现的模式)
topic: 话题关键词(可选,platform_compare模式适用)
date_range: 日期范围,格式: {"start": "YYYY-MM-DD", "end": "YYYY-MM-DD"}
min_frequency: 最小共现频次(keyword_cooccur模式),默认3
top_n: 返回TOP N结果(keyword_cooccur模式),默认20
Returns:
数据洞察分析结果字典
Examples:
- analyze_data_insights_unified(insight_type="platform_compare", topic="人工智能")
- analyze_data_insights_unified(insight_type="platform_activity", date_range={...})
- analyze_data_insights_unified(insight_type="keyword_cooccur", min_frequency=5)
"""
try:
# 参数验证
if insight_type not in ["platform_compare", "platform_activity", "keyword_cooccur"]:
raise InvalidParameterError(
f"无效的洞察类型: {insight_type}",
suggestion="支持的类型: platform_compare, platform_activity, keyword_cooccur"
)
# 根据洞察类型调用相应方法
if insight_type == "platform_compare":
return self.compare_platforms(
topic=topic,
date_range=date_range
)
elif insight_type == "platform_activity":
return self.get_platform_activity_stats(
date_range=date_range
)
else: # keyword_cooccur
return self.analyze_keyword_cooccurrence(
min_frequency=min_frequency,
top_n=top_nView on GitHub (pinned to 8ee26026ba)
Solutions
- Pass an existing splitter: reuse the module's split function used by other senders (e.g. split_content for wework) matching your webhook's byte limit.
- If your content is always short, pass a trivial splitter: lambda text, size: [text] (respecting the batch_size contract).
- Check the function signature/docstring (read with inspect.signature) to confirm the exact parameter name before wiring a custom caller.
- Write a smoke test for the new channel that actually sends to a mock webhook so missing-argument bugs surface in CI.
Example fix
# before
send_generic_webhook(
webhook_url=url,
content=report_text,
split_content_func=None, # ValueError
)
# after
from trendradar.notification.senders import split_content
send_generic_webhook(
webhook_url=url,
content=report_text,
split_content_func=split_content, # batches text to size limit
batch_size=4096,
) Defensive patterns
Strategy: type-guard
Validate before calling
import inspect
def splitter_ok(func) -> bool:
"""Splitter must be callable and accept (content, batch_size)."""
if not callable(func):
return False
try:
sig = inspect.signature(func)
sig.bind("text", 4096)
return True
except TypeError:
return False
assert splitter_ok(split_content_func), "pass a real split function" Type guard
from typing import Callable, List, Optional
def is_split_content_func(func) -> bool:
"""True when func is a callable taking (text, size) — guards the required param."""
if not callable(func):
return False
try:
inspect.signature(func).bind("text", 4096)
return True
except TypeError:
return False Prevention
- Read the signature with inspect.signature before wiring new senders; required callables with no default are contract points.
- Reuse the module's existing splitter instead of writing your own; only substitute one that honors the same batch semantics.
- Add a CI smoke test per notification channel against a mock webhook so missing-parameter bugs fail in tests, not production.
When it happens
Trigger: Calling the send function without passing split_content_func (it has no default), passing split_content_func=None explicitly, or forwarding **kwargs from a dict that never set the key. Also happens when a new caller copies the signature but only fills webhook_url/content.
Common situations: Integrating a new notification channel and forgetting the splitter; refactoring that renames the kwarg (e.g. split_func vs split_content_func) so None arrives; building the kwargs dict dynamically and conditionally skipping the splitter; tests constructing minimal calls.
Related errors
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/f685260a5cc47664.
Report an issue: GitHub.