ZhuLinsen/daily_stock_analysis · error · HTTPException

generation_failed

generation_failed

Error message

生成分享图片所需报告失败: {exc.message}

What it means

When rendering a share image, HistoryService.get_markdown_report can raise MarkdownReportGenerationError; the endpoint maps it to HTTP 500 code=generation_failed '生成分享图片所需报告失败: {exc.message}' (history.py:109-116, re-raised with `from exc`). This means the persisted record exists but its Markdown report could not be (re)generated — typically a failure in report reconstruction from stored analysis data.

Source

Thrown at api/v1/endpoints/history.py:109

) -> tuple[Mapping[str, Any], str]:
    """Load the shared persisted input used by PNG and desktop HTML renderers."""

    service = HistoryService(db_manager)
    result = service.resolve_and_get_detail(record_id)
    if result is None:
        raise HTTPException(
            status_code=404,
            detail={
                "error": "not_found",
                "message": f"未找到 id/query_id={record_id} 的分析记录",
            },
        )

    try:
        markdown_content = service.get_markdown_report(record_id)
    except MarkdownReportGenerationError as exc:
        logger.error("Share image report generation failed for %s: %s", record_id, exc.message)
        raise HTTPException(
            status_code=500,
            detail={
                "error": "generation_failed",
                "message": f"生成分享图片所需报告失败: {exc.message}",
            },
        ) from exc

    if not markdown_content:
        raise HTTPException(
            status_code=404,
            detail={
                "error": "not_found",
                "message": f"未找到 id/query_id={record_id} 的报告内容",
            },
        )
    return result, markdown_content

View on GitHub (pinned to 5159bd72e8)

Solutions

  1. Read the server log line 'Share image report generation failed for <id>: <msg>' — exc.message carries the generation-stage reason
  2. Retry once to rule out transient asset/env issues; then test the same record through the regular markdown-report endpoint to confirm it is record-specific
  3. If record-specific, re-run the analysis for that stock to regenerate a complete record instead of sharing the broken one
  4. For containerized deployments, verify the image includes all report-render assets the history renderer needs
Defensive patterns

Strategy: try-catch

Type guard

def is_generation_failed(resp) -> bool:
    return (
        resp.status_code == 500
        and isinstance(resp.json().get('detail'), dict)
        and resp.json()['detail'].get('error') == 'generation_failed'
    )

Try / catch

try:
    img = get_share_image(record_id)
except HTTPError as e:
    if is_generation_failed(e.response):
        # server log line 'Share image report generation failed for <id>' has the cause
        detail = e.response.json()['detail']['message']
        if is_transient_asset_issue(detail):
            img = get_share_image(record_id)  # one retry
        else:
            flag_record_for_regeneration(record_id)
    else:
        raise

Prevention

When it happens

Trigger: Calling the share-image endpoint for a record whose stored report payload is incomplete or in a legacy format the markdown generator cannot process; template/rendering code paths throwing while rebuilding the document; dependencies of the report renderer (e.g. chart/emoji/font assets) missing in the container. Distinguished from 404 '记录不存在' (error 36) and 404 '报告内容为空' (error 38) by being an active generation failure with an underlying exception.

Common situations: Records written by an older release whose report schema changed; slim containers missing fonts/assets the markdown-to-image pipeline needs; records created with persist paths disabled storing only partial payloads.

Related errors


AI-assisted analysis of ZhuLinsen/daily_stock_analysis@5159bd72e8 (2026-08-15). Data as JSON: /api/errors/cb7469cc22a37d45. Report an issue: GitHub.