Fix issue #1802: Handle UnicodeDecodeError in repo file paths

Added error handling for UnicodeDecodeError when decoding paths in the Git repository.
This issue arises when paths are encoded in formats other than the expected system encoding.

The error handler now provides a detailed error message, helping users identify potential encoding mismatches.

Closes #1802
This commit is contained in:
mdk 2024-12-23 20:01:08 +01:00
parent 083605e2d7
commit 5c92491bc0
2 changed files with 46 additions and 0 deletions

View file

@ -393,6 +393,12 @@ def sanity_check_repo(repo, io):
if not repo.git_repo_error:
return True
error_msg = str(repo.git_repo_error)
except UnicodeDecodeError as exc:
error_msg = (
f"Failed to read the Git repository. This issue is likely caused by a path encoded "
f"in a format different from the expected encoding \"{sys.getfilesystemencoding()}\".\n"
f"Internal error: {str(exc)}"
)
except ANY_GIT_ERROR as exc:
error_msg = str(exc)
bad_ver = "version in (1, 2)" in error_msg