{"record":{"id":"fa2f519f5eea9205","repo":"sansan0/TrendRadar","slug":"stripped-fa2f51","errorCode":null,"errorMessage":"日期解析失败: {stripped}","messagePattern":"日期解析失败: (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":423,"sourceCode":"                )\n        # 3. 尝试自然语言解析\n        else:\n            try:\n                result = DateParser.resolve_date_range_expression(stripped)\n                if result.get(\"success\"):\n                    dr = result[\"date_range\"]\n                    start_date = datetime.strptime(dr[\"start\"], \"%Y-%m-%d\")\n                    end_date = datetime.strptime(dr[\"end\"], \"%Y-%m-%d\")\n                    return (start_date, end_date)\n                else:\n                    raise InvalidParameterError(\n                        f\"无法识别的日期表达式: {stripped}\",\n                        suggestion=\"支持格式: YYYY-MM-DD, {\\\"start\\\": \\\"...\\\", \\\"end\\\": \\\"...\\\"}, 或自然语言（今天、本周、最近7天等）\"\n                    )\n            except InvalidParameterError:\n                raise\n            except Exception:\n                raise InvalidParameterError(\n                    f\"日期解析失败: {stripped}\",\n                    suggestion=\"支持格式: YYYY-MM-DD, {\\\"start\\\": \\\"...\\\", \\\"end\\\": \\\"...\\\"}, 或自然语言（今天、本周、最近7天等）\"\n                )\n\n    if not isinstance(date_range, dict):\n        raise InvalidParameterError(\n            \"date_range 必须是字典类型、日期字符串或有效的JSON字符串\",\n            suggestion='例如: {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"} 或 \"2025-10-01\"'\n        )\n\n    start_str = date_range.get(\"start\")\n    end_str = date_range.get(\"end\")\n\n    if not start_str or not end_str:\n        raise InvalidParameterError(\n            \"date_range 必须包含 start 和 end 字段\",\n            suggestion='例如: {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"}'\n        )","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L405-L441","documentation":"Raised by normalize_date_range's catch-all: the natural-language branch threw an unexpected (non-InvalidParameterError) exception. Looking at the code, after a successful parse it does datetime.strptime(dr['start'], '%Y-%m-%d') — so if DateParser ever returned success with a malformed date string, or any internal bug (KeyError on 'date_range', TypeError, etc.) fired, it is masked as '日期解析失败'.","triggerScenarios":"A DateParser success result whose date_range.start/end are not strict YYYY-MM-DD (e.g. a pattern returns a datetime or different format), or an exception inside resolve_date_range_expression itself (bad regex input type, None field). Essentially: an internal inconsistency rather than a user formatting mistake.","commonSituations":"Server-side bugs after adding a new date expression to DateParser without normalizing output to ISO strings; timezone/locale side effects; None leaking into the result dict. Users cannot fix this by reformatting — the generic message hides the real traceback.","solutions":["As a caller: retry with explicit ISO dates {\"start\": \"...\", \"end\": \"...\"} to bypass the natural-language path entirely","If you own the code: log the original exception (currently swallowed by 'except Exception') to identify the real failure","Audit DateParser._calculate_date_range return values so start/end are always zero-padded YYYY-MM-DD strings","Add a regression test per supported expression asserting strptime succeeds on the output"],"exampleFix":"# before\nexcept Exception:\n    raise InvalidParameterError(f\"日期解析失败: {stripped}\", ...)\n# after\nexcept Exception as e:\n    logger.exception(\"date expression internal failure\")\n    raise InvalidParameterError(f\"日期解析失败: {stripped} (原因: {e})\", ...)","handlingStrategy":"fallback","validationCode":"// Avoid the natural-language path entirely: always send structured ranges\ndate_range = { start: isoDaysAgo(7), end: isoToday() };","typeGuard":null,"tryCatchPattern":"try { call({ date_range: expr }); }\ncatch (e) {\n  if (/日期解析失败/.test(e.message)) {\n    // internal path failed; fall back to explicit ISO range\n    call({ date_range: { start: isoDaysAgo(7), end: isoToday() } });\n  } else throw e;\n}","preventionTips":["Prefer explicit ISO ranges over natural language in production pipelines","Report occurrences to the server maintainer — this error masks an internal bug","If you maintain the server, log the swallowed exception to expose root causes"],"tags":["date-parsing","error-masking","robustness"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}