fix: handle non-UTF-8 files in OpenClaw migration script#8898
Open
chancelu wants to merge 1 commit into
Open
Conversation
On Windows systems with non-UTF-8 default encodings (e.g. GBK on Chinese Windows), the migration script crashes with UnicodeDecodeError when the OpenClaw directory contains binary files (images, SQLite databases) or text files with mixed encodings. Changes: - read_text(): use errors="replace" to gracefully handle non-UTF-8 bytes - load_yaml_file(): catch UnicodeDecodeError alongside YAMLError - parse_env_file(): catch UnicodeDecodeError when reading .env files - load_openclaw_config(): catch UnicodeDecodeError alongside JSONDecodeError - migrate_daily_memory(): add per-file error handling to skip unreadable files Tested on Windows 11 (Chinese locale, GBK default) with an OpenClaw directory containing .jpg, .ogg, .sqlite, and mixed-encoding .md files.
19 tasks
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.