fix: handle non-UTF-8 files in OpenClaw migration script - #8898
Conversation
|
Thanks for addressing the Windows encoding failure. The current main premise is confirmed: Problems
Suggested changes
Automated hermes-sweeper review. |
|
All three issues from the sweeper review are addressed in the latest commit (703949fe):
Ran the full |
703949f to
77534ec
Compare
|
@teknium1 Thanks for the detailed review — rebased onto current main and resolved the conflict in 1. Three remaining strict JSON reads — covered.
I also swept the two other strict readers on the same path — 2. Regression tests — added. Four new tests at the end of
Each plants a single invalid byte ( 3. One explicit recovery policy — done. Every source read now goes through a single policy: decode UTF-8 with Could you re-review and approve the workflow run when you have a moment? Happy to adjust if you'd prefer a different recovery policy (e.g. skip-and-record instead of replace). |
|
Merged via PR #71078 — your commit(s) were cherry-picked onto current main with your authorship preserved in git log (rebase merge). This PR was part of the class-wide close-out of bare |
Problem
On Windows systems with non-UTF-8 default encodings (e.g. GBK on Chinese Windows),
hermes claw migratecrashes withUnicodeDecodeErrorwhen the source OpenClaw directory contains:.jpg,.ogg,.sqlite) inmedia/,memory/, orworkspace/The error occurs during the preview phase, so the migration cannot even show what would be imported:
Root Cause
Several file-reading functions in
openclaw_to_hermes.pyusepath.read_text(encoding="utf-8")without error handling. When any file in the OpenClaw directory tree contains non-UTF-8 bytes, the entire migration aborts.Fix
read_text(): adderrors="replace"to gracefully substitute invalid bytes with U+FFFD instead of crashingload_yaml_file(): catchUnicodeDecodeErroralongsideyaml.YAMLErrorparse_env_file(): catchUnicodeDecodeErrorwhen reading.envfilesload_openclaw_config(): catchUnicodeDecodeErroralongsidejson.JSONDecodeErrormigrate_daily_memory(): add per-file try/except to skip unreadable files instead of aborting the entire loopTesting
Tested on Windows 11 Pro (Chinese locale, GBK default encoding) with an OpenClaw directory containing
.jpg,.ogg,.sqlite, and mixed-encoding.mdfiles. Before the fix,hermes claw migrate --dry-runcrashed immediately. After the fix, it completes successfully and correctly identifies 44 items for migration.