Skip to content

pantry add silently destroys an existing same-named entry of a different kind #695

Closed

Description

@drawmeanelephant

Suggested labels: bug, area: pantry


Discovery audit finding H2 (high) — cooklang/cookcli @ 7c2f48b (v0.38.1), audited 2026-10-12. Repro verified live. Silent data loss in pantry.conf.

Summary

cook pantry add silently destroys an existing same-named entry of a different kind.

Where

  • crates/core/src/pantry/mod.rs:909-919
  • crates/core/src/pantry/edit.rs:137-180 — item_exists only refuses same-kind items; insert then mem::replaces the whole key.

Repro

With config/pantry.conf containing:

[milk]
carton = "2%l"

run:

$ cook pantry add general milk --quantity 3%l   # exit 0
$ cat config/pantry.conf
milk = "3%l"

The whole [milk] section is gone. The same happens when the name is a top-level item (fridge = "2%l" replaced by a [fridge] table) and for [[fridge]] arrays. remove/update/rename_section all refuse these collisions; add does not.

Expected

add refuses the collision with an error (as remove/update do) and leaves pantry.conf unchanged.

Actual

Exit 0 and the pre-existing entry is silently destroyed.

Acceptance criteria (red → green)

  • Red: after the repro command, [milk] carton = "2%l" is gone from pantry.conf.
  • Green: the command errors, exit ≠ 0, and the file still contains the original entry.

Verification

Executed repro; two of the three shapes verified live.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions