sansan0/TrendRadar · error · InvalidParameterError
keyword 不能为空白字符
Error message
keyword 不能为空白字符
What it means
Raised by validate_keyword when the keyword is a string but strip() removes everything — i.e. it consists solely of whitespace (spaces, tabs, newlines, full-width spaces). Distinct from error 57: the input was non-empty, just whitespace-only. The check runs before the 100-char length check.
Source
Thrown at mcp_server/utils/validators.py:504
Args:
keyword: 搜索关键词
Returns:
处理后的关键词
Raises:
InvalidParameterError: 关键词无效
"""
if not keyword:
raise InvalidParameterError("keyword 不能为空")
if not isinstance(keyword, str):
raise InvalidParameterError("keyword 必须是字符串类型")
keyword = keyword.strip()
if not keyword:
raise InvalidParameterError("keyword 不能为空白字符")
if len(keyword) > 100:
raise InvalidParameterError(
"keyword 长度不能超过100个字符",
suggestion="请使用更简洁的关键词"
)
return keyword
def validate_top_n(top_n: Optional[Union[int, str]], default: int = 10) -> int:
"""
验证TOP N参数
Args:
top_n: TOP N数量(整数或字符串)
default: 默认值
View on GitHub (pinned to 8ee26026ba)
Solutions
- Trim the input before calling: keyword.trim() in JS / keyword.strip() in Python, and skip the call if empty
- Sanitize full-width and non-breaking spaces: replace '\u3000' and '\u00a0' with normal spaces before trimming
- Validate with a regex like /\S/ (at least one non-whitespace char) client-side
- Treat whitespace-only input the same as missing input in your UX
Example fix
// before
tool.search({ keyword: " " })
// after
const kw = keyword.replace(/[\u3000\u00a0]/g, " ").trim();
if (kw) tool.search({ keyword: kw }); Defensive patterns
Strategy: validation
Validate before calling
const kw = keyword.replace(/[\u3000\u00a0]/g, ' ').trim();
if (!kw) throw new Error('keyword is whitespace-only'); Type guard
const hasVisibleChar = (v: string): boolean => /\S/.test(v); // any non-whitespace char
Try / catch
try { call({ keyword }); }
catch (e) {
if (/不能为空白字符/.test(e.message)) { /* treat as empty input: prompt user */ throw e; }
else throw e;
} Prevention
- Trim input (including full-width \u3000 and NBSP \u00a0) before sending
- Reject whitespace-only input in the UI, same as empty
- Sanitize CSV/paste sources before they reach the keyword field
When it happens
Trigger: Passing keyword: " ", "\t", "\n", or a full-width space " " (common in CJK input). Also strings that look non-empty in logs but are pure padding, e.g. from CSV cells or template interpolation of empty variables with decorative spaces.
Common situations: Copy-paste from documents including non-breaking/full-width spaces; template strings like f"{term} " collapsing when term is empty; CSV/Excel cells with stray whitespace; LLM emitting whitespace when it means to skip the search.
Related errors
AI-assisted analysis of sansan0/TrendRadar@8ee26026ba (2026-08-15).
Data as JSON: /api/errors/739384220b2adab7.
Report an issue: GitHub.