diff --git a/bot/code_review_bot/revisions/base.py b/bot/code_review_bot/revisions/base.py index 4b2d42bad..991b238a4 100644 --- a/bot/code_review_bot/revisions/base.py +++ b/bot/code_review_bot/revisions/base.py @@ -174,8 +174,8 @@ def get_file_content( try: with (local_cache_repository / file_path).open() as f: file_content = f.read() - except (FileNotFoundError, IsADirectoryError): - logger.warning("Failed to find issue's related file", path=file_path) + except (FileNotFoundError, IsADirectoryError, UnicodeDecodeError): + logger.warning("Failed to read issue's related file", path=file_path) file_content = None else: try: diff --git a/bot/tests/test_revisions.py b/bot/tests/test_revisions.py index 03afc2b07..43e37cc05 100644 --- a/bot/tests/test_revisions.py +++ b/bot/tests/test_revisions.py @@ -93,6 +93,13 @@ def test_autoland(mock_config, mock_revision_autoland): ) +def test_binary_file_content_is_ignored(mock_revision, tmp_path): + binary_file = tmp_path / "artifact.webp" + binary_file.write_bytes(b"RIFF\xac=\x00\x00WEBP") + + assert mock_revision.get_file_content(binary_file.name, tmp_path) is None + + def test_clang_files(mock_revision): """ Test clang files detection