diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index 3e69ec91ec..3814d1ff91 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -87,7 +87,23 @@ def collect( data[rev][repo_path]["data"] = fd.read() except FileNotFoundError: # This might happen simply because cache is absent - pass + logger.debug( + ( + "Could not find '%s' on '%s'. " + "File will not be plotted" + ), + path, + rev, + ) + except UnicodeDecodeError: + logger.debug( + ( + "'%s' at '%s' is binary file. It will not be " + "plotted." + ), + path, + rev, + ) return data diff --git a/tests/func/plots/test_show.py b/tests/func/plots/test_show.py index 5d45c6d328..f7c378a25a 100644 --- a/tests/func/plots/test_show.py +++ b/tests/func/plots/test_show.py @@ -827,3 +827,13 @@ def test_show_dir_plots(tmp_dir, dvc, run_copy_metrics): result = dvc.plots.show(targets=[p1]) assert set(result.keys()) == {p1} + + +def test_ignore_binary_file(tmp_dir, dvc, run_copy_metrics): + with open("file", "wb") as fobj: + fobj.write(b"\xc1") + + run_copy_metrics("file", "plot_file", plots=["plot_file"]) + + with pytest.raises(NoMetricsParsedError): + dvc.plots.show()