Skip to content

Commit 29b95c3

Browse files
authored
live: Catch errors in _ensure_paths_are_tracked_in_dvc_exp. (#555)
For #547
1 parent 34cacc5 commit 29b95c3

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/dvclive/live.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,16 @@ def _ensure_paths_are_tracked_in_dvc_exp(self):
512512
outs_spec = PathSpec.from_lines(
513513
"gitwildmatch", [str(o) for o in self._dvc_repo.index.outs]
514514
)
515-
paths_to_track = [
516-
f
517-
for f in self._dvc_repo.scm.untracked_files()
518-
if (dir_spec.match_file(f) and not outs_spec.match_file(f))
519-
]
520-
if paths_to_track:
521-
self._dvc_repo.scm.add(paths_to_track)
515+
try:
516+
paths_to_track = [
517+
f
518+
for f in self._dvc_repo.scm.untracked_files()
519+
if (dir_spec.match_file(f) and not outs_spec.match_file(f))
520+
]
521+
if paths_to_track:
522+
self._dvc_repo.scm.add(paths_to_track)
523+
except Exception as e: # noqa: BLE001
524+
logger.warning(f"Failed to git add paths:\n{e}")
522525

523526
def save_dvc_exp(self):
524527
if self._save_dvc_exp:

tests/test_dvc.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,13 @@ def test_dvc_outs_are_not_added(tmp_dir, mocked_dvc_repo, monkeypatch):
258258
live.next_step()
259259

260260
live._dvc_repo.scm.add.assert_called_with(["dvclive/metrics.json"])
261+
262+
263+
def test_errors_on_git_add_are_catched(tmp_dir, mocked_dvc_repo, monkeypatch):
264+
monkeypatch.setenv(DVC_EXP_BASELINE_REV, "foo")
265+
monkeypatch.setenv(DVC_EXP_NAME, "bar")
266+
mocked_dvc_repo.scm.untracked_files.return_value = ["dvclive/metrics.json"]
267+
mocked_dvc_repo.scm.add.side_effect = Exception("foo")
268+
269+
with Live(report=None) as live:
270+
live.summary["foo"] = 1

0 commit comments

Comments
 (0)