Skip to content

[refactor][P2] jsonrepair 终态错误无导出哨兵——调用方只能对中文文案做前缀匹配分流 #384

Closed

Description

@zy84338719

来源:2026-11-11 全矩阵深度代码审查(6 路并行扫描约 24 万行 Go)。判定已复核;行号基于 2026-11-11 的 main,动手前请核对现场。
归档索引:#372(本仓重构 backlog)

位置

pkg/jsonrepair/jsonrepair.go:438-439、478;jsonrepair/unmarshal.go:103

证据

三处终态均为裸 fmt.Errorf:"jsonrepair: 空输入"(:439)、"jsonrepair: 无法解析为 JSON"(:478)、"jsonrepair: 无法解析为 JSON(宽松模式无法闭合出合法 JSON)"(unmarshal.go:103)。「空输入」是调用方自己的 bug(应 programmer error 上抛),「无法解析」是 LLM 输出质量问题(应回喂重试)——两类语义完全不同,目前只能 strings.HasPrefix(err.Error(), ...) 中文匹配。

关联

与二轮 #382(Unmarshal 把严格/宽容两路错误 %v 拍平进一条文案)互补不重复——#382 是包装方式,本条是「分类本体从未以哨兵存在」。

建议

导出 ErrEmptyInput / ErrUnparseable 两个哨兵,三处改为 %w 包装;UnmarshalLenient 的宽松失败也并入 ErrUnparseable。

Activity

  1. moved this from Todo to In Progress in oekit Issue 大盘on Nov 12, 2026
  2. added a commit that references this issue on Nov 12, 2026
  3. moved this from In Progress to Done in oekit Issue 大盘on Nov 12, 2026
  4. zy84338719 commented on Nov 12, 2026

    @zy84338719
    ContributorAuthor

    已合入修复 ✅(无 SemVer 发布:本次改动不发版本)

    变更内容

    jsonrepair 导出 ErrEmptyInput/ErrUnparseable 哨兵,三处终态 errors.Is 分流,文案逐字兼容

    合入:PR #423(https://github.com/oekit/pkg/pull/423),merge commit 53135ccf,2026-11-12T17:13:18Z

    CI:link ✅ / Lint & Test / Test ✅ / Lint & Test / Lint ✅ / Zero Third-Party Deps ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactor重构机会(代码审查产出)

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions