mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-09 23:10:24 +01:00
Merge pull request #2777 from pared/2602
import: intercept and rephrase OutputNotFound message
This commit is contained in:
+13
-2
@@ -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
|
||||
)
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
@@ -435,7 +435,7 @@ class Repo(object):
|
||||
|
||||
matched = list(filter(func, outs))
|
||||
if not matched:
|
||||
raise OutputNotFoundError(path)
|
||||
raise OutputNotFoundError(path, self)
|
||||
|
||||
return matched
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user