{"record":{"id":"e98bdcb2ce3419e4","repo":"ZhuLinsen/daily_stock_analysis","slug":"internal-error","errorCode":"internal_error","errorMessage":"回测执行失败: {str(exc)}","messagePattern":"回测执行失败: (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/v1/endpoints/backtest.py","lineNumber":82,"sourceCode":"            code=request.code,\n            force=request.force,\n            eval_window_days=request.eval_window_days,\n            min_age_days=request.min_age_days,\n            analysis_date_from=request.analysis_date_from,\n            analysis_date_to=request.analysis_date_to,\n            limit=request.limit,\n        )\n        return BacktestRunResponse(**stats)\n    except ValueError as exc:\n        raise HTTPException(\n            status_code=400,\n            detail={\"error\": \"invalid_params\", \"message\": str(exc)},\n        )\n    except HTTPException:\n        raise\n    except Exception as exc:\n        logger.error(f\"回测执行失败: {exc}\", exc_info=True)\n        raise HTTPException(\n            status_code=500,\n            detail={\"error\": \"internal_error\", \"message\": f\"回测执行失败: {str(exc)}\"},\n        )\n\n\n@router.get(\n    \"/results\",\n    response_model=BacktestResultsResponse,\n    responses={\n        200: {\"description\": \"回测结果列表\"},\n        400: {\"description\": \"请求参数错误\", \"model\": ErrorResponse},\n        500: {\"description\": \"服务器错误\", \"model\": ErrorResponse},\n    },\n    summary=\"获取回测结果\",\n    description=\"分页获取回测结果，支持按股票代码过滤\",\n)\ndef get_backtest_results(\n    code: Optional[str] = Query(None, description=\"股票代码筛选\"),","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/ZhuLinsen/daily_stock_analysis/blob/5159bd72e8373d215492dff122acc9d389e219c9/api/v1/endpoints/backtest.py#L64-L100","documentation":"POST /backtest/run maps any non-ValueError, non-HTTPException exception to HTTP 500 code=internal_error with message '回测执行失败: {str(exc)}' (backtest.py:79-86). This is the catch-all failure path of the run endpoint: database errors from db_manager, unexpected service bugs, or environment problems inside BacktestService.run_backtest all land here. The original traceback is logged server-side with exc_info=True.","triggerScenarios":"Database unavailable or schema mismatch when the service writes/reads backtest records; a bug in the backtest engine for the specific stock/date window; data-provider exceptions that escape the service's own handling; OutOfMemory/timeout-style failures during a large run.","commonSituations":"SQLite file locked by a concurrent long run; DB not migrated after upgrading the backtest schema; a single pathological stock whose stored analysis rows break an assumption in the aggregation code; resource exhaustion when limit is large.","solutions":["Read the server log for the logged traceback (logger.error ... exc_info=True) — the HTTP message's str(exc) is usually too short to diagnose","Reproduce with a narrower request: single code, small limit, tight date window, to bisect whether the failure is data-specific","Verify DB connectivity/migrations (the same db_manager other endpoints use) and retry once transient locks clear","If it reproduces deterministically, capture code+params+traceback and report it as a bug — there is no client-side fix for this path"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    stats = post_backtest_run(payload)\nexcept HTTPError as e:\n    if e.response.status_code == 500 and '回测执行失败' in e.response.text:\n        stats = post_backtest_run(narrowed_payload)  # single code, small limit\n        if stats is None:\n            report_with_server_traceback(payload)\n    else:\n        raise","preventionTips":["Never auto-retry a 500 unchanged — narrow the request (one code, tight window) first","Watch server logs with exc_info for the real traceback instead of trusting str(exc)","Keep DB migrations in lockstep with API deploys to avoid service-level TypeErrors","Serialize long backtest runs to avoid DB lock spillage"],"tags":["backtest","http-500","internal-error","database"],"backgroundTag":null,"analyzedSha":"5159bd72e8373d215492dff122acc9d389e219c9","analyzedAt":"2026-08-15T01:59:36.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}