Repository: iterative/dvc

Issue:
get: relpath in error message for inexistent `path` is not nice
UPDATE: See https://github.com/iterative/dvc/issues/2430#issuecomment-524546265

---

~~Example:~~

```console
$ dvc get https://github.com/iterative/dvc.org \
          I-dont-exist.zip
ERROR: failed to get ' ' from 'https://github.com/iterative/dvc.org' - you are not
inside of a dvc repository (checked up to mount point '/')
...
```
> Note that https://github.com/iterative/dvc.org is NOT a DVC project.

First of all, the command takes a long time to error out.

Also, `you are not inside of a dvc repository`? I thought `dvc get` "doesn't require an existing DVC project to run in", at least according to [our docs](https://dvc.org/doc/commands-reference/get) (which I wrote 😋).

```console
DVC version: 0.57.0
Python version: 3.7.3
Platform: Darwin-18.7.0-x86_64-i386-64bit
Binary: False
Filesystem type (workspace): ('apfs', '/dev/disk1s1')
```

---

Maybe related to #2309


Comments:
It seems to me that `NoDvcRepoError` should be intercepted [here](https://github.com/iterative/dvc/blob/41351a2df2f36ed04846d5e3d976d6d99b71a151/dvc/external_repo.py#L46) and treated differently than "normal" NoDvcRepo
Not able to reproduce this

```
(3.7.0-dvc) ➜  sfd dvc get https://github.com/iterative/dataset-registry I-dont-exist.zip                                                                                   
ERROR: failed to get 'I-dont-exist.zip' from 'https://github.com/iterative/dataset-registry' - unable to find DVC-file with output '../tmpuig76zzhdvc-repo/I-dont-exist.zip'
                                                                                                                                                                            
Having any troubles?. Hit us up at https://dvc.org/support, we are always happy to help!                                                                                    
```

The relpath in the error msg is not really nice though.
I can confirm this is no longer happening to me either 🤷‍♂  Updated title and description of issue.
Its because `https://github.com/iterative/dataset-registry` became dvc repository 3 days ago.

try:
```
dvc get https://github.com/iterative/dvc.org \         
          I-dont-exist.zip
```
Thanks Pawel. I guess what happened is that https://github.com/iterative/dataset-registry used to be empty when I reported this. And since, I have actually populated it with an actual DVC repo. So this is a valid issue after all! I'll update the description and hide outdated comments.

Patch:
diff --git a/dvc/exceptions.py b/dvc/exceptions.py
--- a/dvc/exceptions.py
+++ b/dvc/exceptions.py
@@ -279,3 +279,10 @@ def __init__(self, ignore_dirname):
             ".dvcignore file should not be in collected dir path: "
             "'{}'".format(ignore_dirname)
         )
+
+
+class UrlNotDvcRepoError(DvcException):
+    def __init__(self, url):
+        super(UrlNotDvcRepoError, self).__init__(
+            "URL '{}' is not a dvc repository.".format(url)
+        )
diff --git a/dvc/repo/get.py b/dvc/repo/get.py
--- a/dvc/repo/get.py
+++ b/dvc/repo/get.py
@@ -1,13 +1,17 @@
+import logging
 import os
 import shortuuid
 
 from dvc.config import Config
+from dvc.exceptions import NotDvcRepoError, UrlNotDvcRepoError
 from dvc.path_info import PathInfo
 from dvc.external_repo import external_repo
 from dvc.state import StateNoop
 from dvc.utils import remove
 from dvc.utils.compat import urlparse
 
+logger = logging.getLogger(__name__)
+
 
 @staticmethod
 def get(url, path, out=None, rev=None):
@@ -48,5 +52,8 @@ def get(url, path, out=None, rev=None):
             o.path_info = PathInfo(os.path.abspath(out))
             with o.repo.state:
                 o.checkout()
+
+    except NotDvcRepoError:
+        raise UrlNotDvcRepoError(url)
     finally:
         remove(tmp_dir)


Test patch:
diff --git a/tests/conftest.py b/tests/conftest.py
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -9,8 +9,7 @@
 from dvc.utils.compat import cast_bytes_py2
 from dvc.remote.ssh.connection import SSHConnection
 from dvc.repo import Repo as DvcRepo
-from .basic_env import TestDirFixture, TestDvcGitFixture
-
+from .basic_env import TestDirFixture, TestDvcGitFixture, TestGitFixture
 
 # Prevent updater and analytics from running their processes
 os.environ[cast_bytes_py2("DVC_TEST")] = cast_bytes_py2("true")
@@ -177,3 +176,11 @@ def _close_pools():
 
     yield
     close_pools()
+
+
+@pytest.fixture
+def git_erepo():
+    repo = TestGitFixture()
+    repo.setUp()
+    yield repo
+    repo.tearDown()
diff --git a/tests/func/test_get.py b/tests/func/test_get.py
--- a/tests/func/test_get.py
+++ b/tests/func/test_get.py
@@ -1,6 +1,9 @@
 import os
 import filecmp
 
+import pytest
+
+from dvc.exceptions import UrlNotDvcRepoError
 from dvc.repo import Repo
 
 from tests.utils import trees_equal
@@ -38,3 +41,8 @@ def test_get_repo_rev(repo_dir, erepo):
     assert os.path.isfile(dst)
     with open(dst, "r+") as fobj:
         assert fobj.read() == "branch"
+
+
+def test_get_from_non_dvc_repo(git_erepo):
+    with pytest.raises(UrlNotDvcRepoError):
+        Repo.get(git_erepo.root_dir, "some_file.zip")