{"record":{"id":"739384220b2adab7","repo":"sansan0/TrendRadar","slug":"keyword-739384","errorCode":null,"errorMessage":"keyword 不能为空白字符","messagePattern":"keyword 不能为空白字符","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":504,"sourceCode":"    Args:\n        keyword: 搜索关键词\n\n    Returns:\n        处理后的关键词\n\n    Raises:\n        InvalidParameterError: 关键词无效\n    \"\"\"\n    if not keyword:\n        raise InvalidParameterError(\"keyword 不能为空\")\n\n    if not isinstance(keyword, str):\n        raise InvalidParameterError(\"keyword 必须是字符串类型\")\n\n    keyword = keyword.strip()\n\n    if not keyword:\n        raise InvalidParameterError(\"keyword 不能为空白字符\")\n\n    if len(keyword) > 100:\n        raise InvalidParameterError(\n            \"keyword 长度不能超过100个字符\",\n            suggestion=\"请使用更简洁的关键词\"\n        )\n\n    return keyword\n\n\ndef validate_top_n(top_n: Optional[Union[int, str]], default: int = 10) -> int:\n    \"\"\"\n    验证TOP N参数\n\n    Args:\n        top_n: TOP N数量（整数或字符串）\n        default: 默认值\n","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L486-L522","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ntool.search({ keyword: \"   \" })\n// after\nconst kw = keyword.replace(/[\\u3000\\u00a0]/g, \" \").trim();\nif (kw) tool.search({ keyword: kw });","handlingStrategy":"validation","validationCode":"const kw = keyword.replace(/[\\u3000\\u00a0]/g, ' ').trim();\nif (!kw) throw new Error('keyword is whitespace-only');","typeGuard":"const hasVisibleChar = (v: string): boolean => /\\S/.test(v); // any non-whitespace char","tryCatchPattern":"try { call({ keyword }); }\ncatch (e) {\n  if (/不能为空白字符/.test(e.message)) { /* treat as empty input: prompt user */ throw e; }\n  else throw e;\n}","preventionTips":["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"],"tags":["keyword","whitespace","sanitization","validation"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}