{"record":{"id":"aa5eeb94b9103333","repo":"sansan0/TrendRadar","slug":"keyword","errorCode":null,"errorMessage":"keyword 不能为空","messagePattern":"keyword 不能为空","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":496,"sourceCode":"\n    return (start_date, end_date)\n\n\ndef validate_keyword(keyword: str) -> str:\n    \"\"\"\n    验证关键词\n\n    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","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L478-L514","documentation":"Raised by validate_keyword on the very first check: if not keyword. This catches None and '' (empty string) before any type or content checks. A keyword search requires a non-empty term; there is no 'match all' via empty keyword.","triggerScenarios":"Calling a search tool with keyword: \"\" or keyword: null; optional search fields forwarded verbatim when the user typed nothing; destructured objects with missing keyword key (undefined → None at the Python boundary).","commonSituations":"Forms submitted with empty search box; pipelines passing an empty default ''; LLM omitting the argument where the schema marked it required; conditional expressions collapsing to empty string.","solutions":["Require the user/LLM to provide an actual term before calling; skip the call if keyword is empty","Default to a meaningful term or use a list-all tool (if available) instead of empty-keyword search","Guard client-side: if (!keyword?.trim()) return early","If the field is genuinely optional in your flow, check the tool schema — keyword here is mandatory"],"exampleFix":"// before\ntool.search({ keyword: \"\" })\n// after\nif (!keyword || !keyword.trim()) throw new Error(\"keyword required\");\ntool.search({ keyword })","handlingStrategy":"validation","validationCode":"if (keyword == null || keyword === '') {\n  throw new Error('keyword is required'); // or skip the call\n}","typeGuard":"const isNonEmptyKeyword = (v: unknown): v is string => typeof v === 'string' && v.length > 0;","tryCatchPattern":"try { call({ keyword }); }\ncatch (e) {\n  if (/keyword 不能为空/.test(e.message)) { /* prompt user, do not blind-retry */ throw e; }\n  else throw e;\n}","preventionTips":["Skip the tool call when the search box is empty","Mark keyword required in your client form/LLM schema","Never default a missing keyword to ''"],"tags":["keyword","required-field","search","validation"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}