{"record":{"id":"439ae66a400111c3","repo":"datawhalechina/hello-agents","slug":"error-439ae6","errorCode":null,"errorMessage":"需求不能为空","messagePattern":"需求不能为空","errorType":"exception","errorClass":"WorkflowExecutionError","httpStatus":null,"severity":"error","filePath":"Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py","lineNumber":121,"sourceCode":"            quality=quality,\n        )\n\n    @staticmethod\n    def save_report(result: WorkflowResult, output_path: str | Path) -> Path:\n        \"\"\"以 UTF-8 保存最终 Markdown 报告。\"\"\"\n\n        path = Path(output_path)\n        path.parent.mkdir(parents=True, exist_ok=True)\n        path.write_text(result.report.rstrip() + \"\\n\", encoding=\"utf-8\")\n        return path\n\n    @staticmethod\n    def _validate_requirement(requirement: str) -> str:\n        if not isinstance(requirement, str):\n            raise WorkflowExecutionError(\"需求必须是字符串\")\n        requirement = requirement.strip()\n        if not requirement:\n            raise WorkflowExecutionError(\"需求不能为空\")\n        if len(requirement) > MAX_REQUIREMENT_LENGTH:\n            raise WorkflowExecutionError(\n                f\"需求文本不能超过 {MAX_REQUIREMENT_LENGTH} 个字符\"\n            )\n        return requirement\n\n    @staticmethod\n    def _run_agent(stage: str, agent: AgentLike, prompt: str) -> str:\n        try:\n            response = agent.run(prompt)\n        except Exception as exc:\n            raise WorkflowExecutionError(f\"{stage}阶段执行失败：{exc}\") from exc\n        if not isinstance(response, str) or not response.strip():\n            raise WorkflowExecutionError(f\"{stage}阶段返回了空结果\")\n        return response.strip()\n\n    def _run_tool(\n        self, name: str, parameters: dict[str, object], stage: str","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/zenith191-RequirementClarifierAgent/src/workflow.py#L103-L139","documentation":"Raised by _validate_requirement after stripping the input: a requirement that is all whitespace (or empty) is rejected. The strip-then-check means '   ' fails exactly like ''. This guards the LLM pipeline from being invoked with a prompt that contains no actual requirement text.","triggerScenarios":"Calling run('') or run('   \\n\\t') — e.g. an empty textarea submitted, a blank line read from a file loop, or a variable that defaulted to ''.","commonSituations":"Web form submitted without required-field validation; batch-processing a file where some entries are blank; whitespace from copy-paste or template rendering ('{{ requirement }}' with missing variable).","solutions":["Check and reject empty input in the UI/API layer before invoking the workflow.","Trim user input client-side and server-side; require a minimum length.","For batch jobs, skip blank lines/records instead of passing them to run()."],"exampleFix":"# before\nresult = workflow.run(user_input)\n\n# after\nif not (user_input := user_input.strip()):\n    raise ValueError(\"requirement is empty\")\nresult = workflow.run(user_input)","handlingStrategy":"validation","validationCode":"requirement = (requirement or \"\").strip()\nif not requirement:\n    raise ValueError(\"requirement must be non-empty\")\nresult = workflow.run(requirement)","typeGuard":"def is_nonempty_requirement(v: object) -> bool:\n    return isinstance(v, str) and len(v.strip()) > 0","tryCatchPattern":"try:\n    result = workflow.run(requirement)\nexcept WorkflowExecutionError as e:\n    if \"不能为空\" in str(e):\n        return \"Please provide a requirement\"  # e.g. an API 400 response\n    raise","preventionTips":["Mark the requirement field required in forms/APIs; validate before submit.","Trim inputs client-side and reject blank submissions early.","In batch mode, skip whitespace-only records instead of processing them."],"tags":["python","validation","empty-input","workflow"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}