Skip to content

fix: mine --dry-run TypeError on files with room=None (#586)#687

Merged
bensig merged 2 commits intoMemPalace:developfrom
mvalentsev:fix/dry-run-room-none
Apr 12, 2026
Merged

fix: mine --dry-run TypeError on files with room=None (#586)#687
bensig merged 2 commits intoMemPalace:developfrom
mvalentsev:fix/dry-run-room-none

Conversation

@mvalentsev
Copy link
Copy Markdown
Contributor

Closes #586.

mempalace mine --dry-run crashes with a TypeError in the summary printer when process_file() returns (0, None) for unreadable or too-short files. In real mine mode the drawers == 0 and not dry_run guard skips these entries before they reach room_counts, but in dry-run mode the guard does not fire and None ends up as a dict key. The f-string format {room:20} then raises TypeError: unsupported format string passed to NoneType.__format__.

Fix (2 files, +31/-3):

mempalace/miner.py:

  • Three return 0, None paths in process_file() (already-mined, OSError, below MIN_CHUNK_SIZE) now return return 0, "general" instead. This makes the function contract explicit -- it always returns (int, str).

tests/test_miner.py:

  • New test_mine_dry_run_with_tiny_file_no_crash -- creates a project with one normal file and one below MIN_CHUNK_SIZE, runs mine() with dry_run=True, verifies no crash.

Matches the Option 2 consensus from the issue thread (normalize at the source rather than patching the caller).

process_file() returned (0, None) for already-mined, unreadable, and
too-short files.  In --dry-run mode the caller always enters the
room_counts branch, so None ended up as a dict key and crashed the
summary printer with "unsupported format string passed to
NoneType.__format__".

Returning "general" instead of None makes the function contract
explicit: it always yields (int, str).  This matches the consensus
fix discussed in the issue thread.
@mvalentsev mvalentsev marked this pull request as ready for review April 12, 2026 07:40
Copy link
Copy Markdown
Collaborator

@bensig bensig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review + security audit clean.

@bensig bensig merged commit 091c2fe into MemPalace:develop Apr 12, 2026
6 checks passed
jphein added a commit to jphein/mempalace that referenced this pull request Apr 12, 2026
Upstream merged MemPalace#682-684 (our splits), MemPalace#687 (dry-run None room),
MemPalace#695/MemPalace#708 (convo_miner full response), MemPalace#732 (0-chunk re-processing),
plus VitePress docs site. Conflicts:
- config.py: take upstream's [^\W_] regex (our MemPalace#683 merged version)
- miner.py: integrate upstream's early-return for tiny files, dedupe
  dry-run read path
- test_miner.py: keep our detect_room tests + upstream's dry-run test
- CONTRIBUTING.md: take upstream's org URL update

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@igorls igorls mentioned this pull request Apr 13, 2026
4 tasks
gnusam pushed a commit to gnusam/mempalace-pgsql that referenced this pull request Apr 25, 2026
Port of upstream 091c2fe (PR MemPalace#687, fixes MemPalace#586). The four early-exit
paths in process_file() previously returned (0, None). In dry-run mode
the caller always enters the room_counts branch, so None landed as a
dict key and crashed the summary printer with "unsupported format
string passed to NoneType.__format__".

Returning "general" makes the function contract explicit: it always
yields (int, str). Matches the consensus fix from the upstream issue
thread.

Updated the existing test_process_file_skips_machine_generated_long_lines
assertion accordingly — its previous `assert room is None` was
codifying the bug.

Upstream: MemPalace@091c2fe

Co-authored-by: Mikhail Valentsev <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: mempalace mine --dry-run crashes with TypeError on files assigned room=None

2 participants