Skip to content

fix: prevent UnicodeEncodeError on Windows in search output - #81

Closed
ThanhNguyxn07 wants to merge 4 commits into
MemPalace:mainfrom
ThanhNguyxn07:fix-windows-unicode-encoding
Closed

fix: prevent UnicodeEncodeError on Windows in search output#81
ThanhNguyxn07 wants to merge 4 commits into
MemPalace:mainfrom
ThanhNguyxn07:fix-windows-unicode-encoding

Conversation

@ThanhNguyxn07

Copy link
Copy Markdown

Summary

  • Replace the Unicode box-drawing separator character (─) in mempalace/searcher.py with a plain ASCII dash (-).
  • This prevents UnicodeEncodeError crashes on Windows consoles using cp1252 encoding.

Why

Issue #47 reports that mempalace search crashes on Windows when printing Unicode box-drawing characters:

  • UnicodeEncodeError: 'charmap' codec can't encode characters ...`n
    Using an ASCII separator preserves output formatting while ensuring compatibility across platforms and terminal encodings.

Validation

  • Ran focused regression test for this behavior:
    • pytest tests/test_searcher.py -v (pass)

Notes

  • Change is minimal and isolated to output formatting.
  • No behavior change to search results or query logic.

… Windows encoding errors

This addresses issue MemPalace#47 where the Unicode box-drawing character '─' (U+2500)
in searcher.py caused UnicodeEncodeError crashes on Windows systems using
the cp1252 encoding. The character has been replaced with a standard ASCII
dash '-' to ensure compatibility across all platforms.
…it command argument parsing

This commit addresses two issues:

1. For the Unicode encoding issue on Windows:
- Added _ensure_utf8_encoding() function to handle UTF-8 encoding properly on Windows
- Implemented proper encoding reconfiguration for stdout when running on Windows
- Restored the original Unicode box-drawing character (─) which is now properly handled

2. For the split command issue (MemPalace#63):
- Fixed cmd_split function to pass directory as --source argument instead of positional argument
- This resolves the argument parsing error when running 'mempalace split <dir>'
- The split command now correctly passes arguments to the underlying split_mega_files module
@bensig

bensig commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Thanks — the split fix and expanduser fix are good catches, but this PR overlaps heavily with changes already merged in #114, #119, and #78. Could you split this into just the Windows Unicode fix (searcher.py output encoding) and the config.py expanduser fix as separate PRs?

@bensig bensig closed this Apr 7, 2026
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.

2 participants