Skip to content

Handle decode errors on github files #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/gurubase-backend/backend/core/github/data_source_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,15 @@ def clone_repository(repo_url):
def get_file_content(file_path):
"""Read and return the content of a file."""
try:
with open(file_path, 'r', encoding='utf-8') as f:
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
return f.read()
except UnicodeDecodeError:
except UnicodeDecodeError as e:
logger.error(f"UnicodeDecodeError reading file {file_path}: {str(e)}")
# Skip binary files
return None
return ''
except Exception as e:
logger.warning(f"Error reading file {file_path}: {str(e)}")
return None
logger.error(f"Error reading file {file_path}: {str(e)}")
return ''

def read_repository(repo_path, include=True, glob_pattern=None):
"""Get the directory structure and file contents of the repository.
Expand Down