{"record":{"id":"de5c40688f9cecb2","repo":"sansan0/TrendRadar","slug":"stripped-de5c40","errorCode":null,"errorMessage":"无法识别的日期表达式: {stripped}","messagePattern":"无法识别的日期表达式: (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/validators.py","lineNumber":416,"sourceCode":"            try:\n                single_date = datetime.strptime(stripped, \"%Y-%m-%d\")\n                return (single_date, single_date)\n            except ValueError:\n                raise InvalidParameterError(\n                    f\"日期格式错误: {stripped}\",\n                    suggestion=\"请使用 YYYY-MM-DD 格式，例如: 2025-10-11\"\n                )\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\")","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/validators.py#L398-L434","documentation":"Raised by normalize_date_range when the string branch falls through to natural-language parsing and DateParser.resolve_date_range_expression returns success=False (i.e. error 40 propagated through this path). The suggestion lists all accepted forms: ISO date, JSON object, or supported natural-language phrases (今天, 本周, 最近7天, etc.).","triggerScenarios":"Passing date_range: \"past week\" or \"前天\" or \"Q3 2025\" — anything that is not 10-char ISO, not JSON-shaped, and not in DateParser's supported phrase set. This is the same root cause as error 40 but reached via the validators layer.","commonSituations":"LLM clients inventing date phrases; users trying relative forms the regexes don't cover ('next week', '本月至今'); abbreviations like 'this wk'.","solutions":["Use a supported phrase (今天/昨天/本周/上周/本月/上月/最近N天) or exact ISO dates","Send {\"start\": \"...\", \"end\": \"...\"} for any range not expressible by a supported phrase","Extend DateParser's patterns if you own the server, and keep the phrase list in the suggestion in sync","Normalize user input to ISO dates before invoking the tool"],"exampleFix":"// before\n{\"date_range\": \"past week\"}\n// after\n{\"date_range\": \"last 7 days\"}","handlingStrategy":"validation","validationCode":"const ok = /^(今天|昨天|本周|上周|本月|上月|最近\\d+天|today|yesterday|this week|last week|this month|last month|(?:last|past)\\s+\\d+\\s+days?)$/i.test(s);\nif (!ok) s = 'last 7 days';","typeGuard":"function isSupportedExpression(s: string): boolean {\n  return /^(今天|昨天|本周|上周|本月|上月|最近\\d+天|today|yesterday|this week|last week|this month|last month|(?:last|past)\\s+\\d+\\s+days?)$/i.test(s.trim());\n}","tryCatchPattern":"try { call({ date_range: expr }); }\ncatch (e) {\n  if (/无法识别的日期表达式/.test(e.message)) call({ date_range: { start: isoDaysAgo(7), end: isoToday() } });\n  else throw e;\n}","preventionTips":["Offer users a fixed set of date phrases; convert everything else to ISO","Compute ranges client-side for anything non-trivial","Keep the supported-phrase list synced with the server version you target"],"tags":["date-range","natural-language","validation"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}