{"record":{"id":"173f0c0ea6152a31","repo":"sansan0/TrendRadar","slug":"expression","errorCode":null,"errorMessage":"无法识别的日期表达式: {expression}","messagePattern":"无法识别的日期表达式: (.+?)","errorType":"validation","errorClass":"InvalidParameterError","httpStatus":null,"severity":"error","filePath":"mcp_server/utils/date_parser.py","lineNumber":403,"sourceCode":"            # 中文: 最近N天\n            cn_match = re.match(r'最近(\\d+)天', expression_lower)\n            if cn_match:\n                days = int(cn_match.group(1))\n                normalized = f\"last_{days}_days\"\n\n            # 英文: last N days\n            en_match = re.match(r'(?:last|past)\\s+(\\d+)\\s+days?', expression_lower)\n            if en_match:\n                days = int(en_match.group(1))\n                normalized = f\"last_{days}_days\"\n\n        if not normalized:\n            # 提供支持的表达式列表\n            supported_cn = [\"今天\", \"昨天\", \"本周\", \"上周\", \"本月\", \"上月\",\n                           \"最近7天\", \"最近30天\", \"最近N天\"]\n            supported_en = [\"today\", \"yesterday\", \"this week\", \"last week\",\n                           \"this month\", \"last month\", \"last 7 days\", \"last N days\"]\n            raise InvalidParameterError(\n                f\"无法识别的日期表达式: {expression}\",\n                suggestion=f\"支持的表达式:\\n中文: {', '.join(supported_cn)}\\n英文: {', '.join(supported_en)}\"\n            )\n\n        # 3. 根据 normalized 类型计算日期范围\n        start_date, end_date, description = DateParser._calculate_date_range(\n            normalized, today\n        )\n\n        return {\n            \"success\": True,\n            \"expression\": expression,\n            \"normalized\": normalized,\n            \"date_range\": {\n                \"start\": start_date.strftime(\"%Y-%m-%d\"),\n                \"end\": end_date.strftime(\"%Y-%m-%d\")\n            },\n            \"current_date\": today_str,","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/sansan0/TrendRadar/blob/8ee26026ba6c11dec41a95fb3895a7162876caa1/mcp_server/utils/date_parser.py#L385-L421","documentation":"Raised by DateParser.resolve_date_range_expression when a natural-language date expression matches none of the supported Chinese or English patterns (e.g. 今天/昨天/本周/最近N天, today/last N days). The parser first normalizes the expression via regex matching; if normalization yields nothing, it rejects the input as unrecognizable. The suggestion lists all supported expressions in both languages.","triggerScenarios":"Calling a tool that accepts a date_range expression (e.g. resolve_date_range_expression('past week'), '前天', 'last 3 weeks', '本周一') with any phrase outside the hardcoded pattern set. Typos, unsupported relative forms, or non-CN/EN languages (e.g. Japanese, abbreviations like 'yday') all fall through to this raise.","commonSituations":"LLM-driven MCP clients freely generating date phrases; users assuming arbitrary natural language is supported; mixed-language input like 'this 本周'; singular/plural or article variants ('in the last 7 days') that the regex does not tolerate.","solutions":["Use one of the supported expressions listed in the suggestion: 今天, 昨天, 本周, 上周, 本月, 上月, 最近N天 (CN) or today, yesterday, this week, last week, this month, last month, last N days (EN)","If you need an exact range, bypass the parser and pass explicit dates: {\"start\": \"2025-10-01\", \"end\": \"2025-10-11\"} or a single \"YYYY-MM-DD\" string","If you control the codebase, extend the regex patterns in DateParser (e.g. add '(?:in the )?(?:last|past)\\s+(\\d+)\\s+days?' or '前天') and add the phrase to the supported lists in the error suggestion","Pre-normalize free-text on the caller side into a canonical expression before calling the tool"],"exampleFix":"// before\nDateParser.resolve_date_range_expression(\"past week\")\n// after\nDateParser.resolve_date_range_expression(\"last 7 days\")","handlingStrategy":"validation","validationCode":"const SUPPORTED = /^(今天|昨天|本周|上周|本月|上月|最近\\d+天|today|yesterday|this week|last week|this month|last month|(?:last|past)\\s+\\d+\\s+days?)$/i;\nif (!SUPPORTED.test(expr.trim())) {\n  expr = 'last 7 days'; // or convert to explicit {start, end}\n}","typeGuard":"function isSupportedDateExpression(e: string): boolean {\n  return /^(今天|昨天|本周|上周|本月|上月|最近\\d+天|today|yesterday|this week|last week|this month|last month|(?:last|past)\\s+\\d+\\s+days?)$/i.test(e.trim());\n}","tryCatchPattern":"try {\n  const r = DateParser.resolve_date_range_expression(expr);\n} catch (e) {\n  if (e.message.includes('无法识别的日期表达式')) {\n    // fall back to explicit ISO range computed client-side\n    range = { start: isoDaysAgo(7), end: isoToday() };\n  } else throw e;\n}","preventionTips":["Restrict client-side date-expression inputs to a dropdown of supported phrases","Convert free-text to explicit {start, end} ISO dates before calling the tool","Cache the supported-phrase list from the error suggestion and validate against it"],"tags":["date-parsing","natural-language","validation","mcp"],"backgroundTag":null,"analyzedSha":"8ee26026ba6c11dec41a95fb3895a7162876caa1","analyzedAt":"2026-08-15T01:42:18.084Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}