Skip to content

Commit

Permalink
import: error message when imported file does not exist (#6240)
Browse files Browse the repository at this point in the history
* Fix exception handling

* Replace exceptions with PathMissingError
  • Loading branch information
mmeendez8 authored Jun 30, 2021
1 parent 87cdbf8 commit cc5ba98
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
20 changes: 13 additions & 7 deletions dvc/dependency/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_used_objs(
self, **kwargs
) -> Dict[Optional["ObjectDB"], Set["HashFile"]]:
from dvc.config import NoRemoteError
from dvc.exceptions import NoOutputOrStageError
from dvc.exceptions import NoOutputOrStageError, PathMissingError
from dvc.objects.db.git import GitObjectDB
from dvc.objects.stage import stage

Expand Down Expand Up @@ -126,12 +126,18 @@ def get_used_objs(
except (NoRemoteError, NoOutputOrStageError):
pass

staged_obj = stage(
local_odb,
path_info,
repo.repo_fs,
local_odb.fs.PARAM_CHECKSUM,
)
try:
staged_obj = stage(
local_odb,
path_info,
repo.repo_fs,
local_odb.fs.PARAM_CHECKSUM,
)
except FileNotFoundError as exc:
raise PathMissingError(
self.def_path, self.def_repo[self.PARAM_URL]
) from exc

self._staged_objs[rev] = staged_obj
git_odb = GitObjectDB(repo.repo_fs, repo.root_dir)
used_objs[git_odb].add(staged_obj)
Expand Down
8 changes: 4 additions & 4 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dvc.data_cloud as cloud
from dvc.config import NoRemoteError
from dvc.dvcfile import Dvcfile
from dvc.exceptions import DownloadError
from dvc.exceptions import DownloadError, PathMissingError
from dvc.objects.db import ODBManager
from dvc.stage.exceptions import StagePathNotFoundError
from dvc.system import System
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_push_wildcard_from_bare_git_repo(
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
with dvc_repo.chdir():
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dirextra")
with pytest.raises(FileNotFoundError):
with pytest.raises(PathMissingError):
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dir123")


Expand Down Expand Up @@ -347,11 +347,11 @@ def test_pull_non_workspace(tmp_dir, scm, dvc, erepo_dir):


def test_import_non_existing(erepo_dir, tmp_dir, dvc):
with pytest.raises(FileNotFoundError):
with pytest.raises(PathMissingError):
tmp_dir.dvc.imp(os.fspath(erepo_dir), "invalid_output")

# https://github.com/iterative/dvc/pull/2837#discussion_r352123053
with pytest.raises(FileNotFoundError):
with pytest.raises(PathMissingError):
tmp_dir.dvc.imp(os.fspath(erepo_dir), "/root/", "root")


Expand Down

0 comments on commit cc5ba98

Please sign in to comment.