datawhalechina/hello-agents · warning · HTTPException
str(e)
Error message
str(e)
What it means
A catch-all 500 from POST /writing/explain in api/routes/writing.py. The endpoint body only returns a hardcoded mock dict (explanation is a placeholder template string), so the except branch is unreachable with the current code; the literal timestamp '2024-01-15T10:30:00Z' and fake examples confirm this is stubbed functionality. If triggered after someone adds real logic, it indicates that implementation raised unexpectedly.
Source
Thrown at Co-creation-projects/Apricity-InnocoreAI/api/routes/writing.py:155
logger.error(f"写作助手处理失败: {str(e)}")
raise HTTPException(status_code=500, detail=f"处理失败: {str(e)}")
@router.post("/explain", response_model=Dict[str, Any])
async def explain_concept(request: ExplainRequest):
"""解释复杂概念"""
try:
# 模拟概念解释
return {
"success": True,
"concept": request.concept,
"explanation": f"[Detailed explanation of {request.concept} in accessible terms while maintaining technical accuracy]",
"examples": ["Example 1", "Example 2"],
"timestamp": "2024-01-15T10:30:00Z"
}
except Exception as e:
logger.error(f"概念解释失败: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
@router.post("/polish", response_model=Dict[str, Any])
async def polish_text(request: PolishRequest):
"""润色文本"""
try:
# 模拟文本润色
return {
"success": True,
"original": request.text,
"improved": f"Based on {request.target_style} writing standards, the text can be improved: [Enhanced version]",
"suggestions": ["Use more precise terminology", "Improve sentence structure"],
"timestamp": "2024-01-15T10:30:00Z"
}
except Exception as e:
logger.error(f"文本润色失败: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
View on GitHub (pinned to 606a07d341)
Solutions
- Recognize this endpoint is a stub — if you need real explanations, implement them and add specific exception handling
- When implementing, catch the LLM client's specific exceptions and return 502/503 rather than 500
- Replace detail=str(e) with a static message; log full traceback with logger.exception
- Remove the try/except while it is still a pure mock, so dead code does not imply real error handling
Example fix
# before
except Exception as e:
logger.error(f"概念解释失败: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
# after (real implementation)
result = await llm.explain(request.concept) # specific errors handled by caller
except LLMError:
logger.exception("概念解释失败")
raise HTTPException(status_code=502, detail="概念解释服务不可用") Defensive patterns
Strategy: validation
Validate before calling
// Endpoint is a stub; validate expectations client-side instead of relying on it
const resp = await fetch('/writing/explain', ...);
const data = await resp.json();
if (data.explanation?.startsWith('[')) console.warn('explain endpoint returned mock data'); Try / catch
try:
data = client.post('/writing/explain', json={'concept': c})
except HTTPError:
# stub cannot fail; a 500 means real logic was added — check server logs
raise Prevention
- Do not build features on this endpoint until it has a real implementation — responses are placeholders
- Feature-flag mock endpoints so clients can detect and skip them
- If you implement it, add tests for the failure path before shipping
When it happens
Trigger: With the shipped mock body: essentially never (dict literals with f-strings on safe inputs do not raise). After replacing the mock with a real LLM call: any client/network/quota error, or logger being None. Triggered by any POST to /writing/explain once real code is added.
Common situations: Developers wire a real explainer into the endpoint and hit OpenAI auth/timeout errors; reviewers flag the endpoint during audits because it returns fabricated data; tests asserting real explanations fail against the mock.
Related errors
AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14).
Data as JSON: /api/errors/6fc669693c63cbb3.
Report an issue: GitHub.