Merge pull request #2777 from pared/2602

import: intercept and rephrase OutputNotFound message
This commit is contained in:
Ruslan Kuprieiev
2019-11-20 06:27:58 +02:00
committed by GitHub
4 changed files with 26 additions and 4 deletions
+13 -2
View File
@@ -59,10 +59,12 @@ class OutputNotFoundError(DvcException):
output (unicode): path to the file/directory.
"""
def __init__(self, output):
def __init__(self, output, repo=None):
self.output = output
self.repo = repo
super(OutputNotFoundError, self).__init__(
"unable to find DVC-file with output '{path}'".format(
path=relpath(output)
path=relpath(self.output)
)
)
@@ -338,3 +340,12 @@ class RemoteNotSpecifiedInExternalRepoError(DvcException):
),
cause=cause,
)
class NoOutputInExternalRepoError(DvcException):
def __init__(self, path, external_repo_path, external_repo_url):
super(NoOutputInExternalRepoError, self).__init__(
"Output '{}' not found in target repository '{}'".format(
relpath(path, external_repo_path), external_repo_url
)
)
+6
View File
@@ -9,6 +9,8 @@ from funcy import retry
from dvc.config import NoRemoteError
from dvc.exceptions import RemoteNotSpecifiedInExternalRepoError
from dvc.exceptions import NoOutputInExternalRepoError
from dvc.exceptions import OutputNotFoundError
from dvc.utils.fs import remove
@@ -25,6 +27,10 @@ def external_repo(url=None, rev=None, rev_lock=None, cache_dir=None):
yield repo
except NoRemoteError as exc:
raise RemoteNotSpecifiedInExternalRepoError(url, cause=exc)
except OutputNotFoundError as exc:
if exc.repo is repo:
raise NoOutputInExternalRepoError(exc.output, repo.root_dir, url)
raise
repo.close()
+1 -1
View File
@@ -435,7 +435,7 @@ class Repo(object):
matched = list(filter(func, outs))
if not matched:
raise OutputNotFoundError(path)
raise OutputNotFoundError(path, self)
return matched
+6 -1
View File
@@ -8,7 +8,7 @@ import pytest
from mock import patch
from dvc.config import Config
from dvc.exceptions import DownloadError
from dvc.exceptions import DownloadError, NoOutputInExternalRepoError
from dvc.stage import Stage
from dvc.system import System
from dvc.utils import makedirs
@@ -154,3 +154,8 @@ def test_pull_non_workspace(git, dvc_repo, erepo):
os.remove(stage.outs[0].cache_path)
dvc_repo.fetch(all_tags=True)
assert os.path.exists(stage.outs[0].cache_path)
def test_import_non_existing(dvc_repo, erepo):
with pytest.raises(NoOutputInExternalRepoError):
dvc_repo.imp(erepo.root_dir, "invalid_output")