Skip to content

-s 策略模式:Cannot read properties of undefined (reading 'split') 导致生成失败 #5

@LLM-X-Factorer

Description

@LLM-X-Factorer

问题描述

使用 -s 策略模式时,LLM 策略成功生成(✔ 策略生成完成: 6 个标题, 7 张卡片),但后续生成图片时报 Cannot read properties of undefined (reading 'split') 错误,导致整个流程失败且未触发 fallback。

复现

md2red generate -s xhs-post-02-ai-citation-source.md -o output/

输出:

ℹ 调用 gemini (gemini-2.5-flash) 生成内容策略...
✔ 策略生成完成: 6 个标题, 7 张卡片
✖ 生成失败: Cannot read properties of undefined (reading 'split')

分析

错误发生在策略生成之后的图片渲染阶段,说明 LLM 返回的策略 JSON 中某个卡片的字段为 undefined(可能是 contenttitle 缺失),然后代码尝试对该字段调用 .split()

建议:

  1. 在使用策略 JSON 的字段前做 null/undefined 检查
  2. 此类渲染阶段的错误也应触发 fallback 到直接模式(当前 fallback 只覆盖策略生成阶段的错误)

环境

  • md2red: 最新 main (b6f03ca)
  • LLM: gemini-2.5-flash
  • 输入: 约 900 字中文 Markdown,7 个 H2 章节
  • 复现率: 1/10 篇(xhs-post-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions