diff --git a/bot/code_review_bot/revisions/base.py b/bot/code_review_bot/revisions/base.py index 4b2d42bad..ac859ae5d 100644 --- a/bot/code_review_bot/revisions/base.py +++ b/bot/code_review_bot/revisions/base.py @@ -177,6 +177,12 @@ def get_file_content( except (FileNotFoundError, IsADirectoryError): logger.warning("Failed to find issue's related file", path=file_path) file_content = None + except UnicodeDecodeError: + logger.warning( + "Failed to decode issue's related file, it is not text", + path=file_path, + ) + file_content = None else: try: file_content = self.load_file(file_path) 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