Skip to content

[refactor][P3] pack.NewWriter 不校验 formatVersion,非法值延迟到首次 AddJSONL 才报错且永久毒化 Writer #389

Closed

Description

@zy84338719

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

位置

pkg/pack/pack.go:66-83(构造无校验)、101-104(延迟校验+毒化)

证据

NewWriter 对 formatVersion <= 0 静默接受;首次 AddJSONL 才 if w.version <= 0 { w.err = errors.New("pack: 格式版本必须为正整数"); return 0, w.err }——w.err 置位后所有后续 AddJSONL/Close 永久失败。同仓 webhook.NewHMACValidator、mathx.Clamp、tarx 的 nil 选项 panic、cron.NewDelaySchedule 都是构造期 fail-fast(总则①);唯独版本这个纯参数校验漏在构造期外。

建议

NewWriter 里 if formatVersion <= 0 { panic(...) }(或改为带 error 返回的 NewWriterE,与 MemGroup 口径一致);AddJSONL 里的延迟分支随之删除。

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 发布:本次改动不发版本)

    变更内容

    pack.NewWriter 构造期校验 formatVersion(fail-fast panic),AddJSONL 延迟毒化分支删除

    合入:PR #421(https://github.com/oekit/pkg/pull/421),merge commit 63917515,2026-11-12T17:10:03Z

    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