Skip to content

Commit

Permalink
fs: raise RemoteNotFoundError (#6375)
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Aug 2, 2021
1 parent 15de826 commit 8d71c38
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 9 additions & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ def __init__(self, msg):
super().__init__(f"config file error: {msg}")


class NoRemoteError(ConfigError):
class RemoteConfigError(ConfigError):
pass


class NoRemoteError(RemoteConfigError):
pass


class RemoteNotFoundError(RemoteConfigError):
pass


Expand Down
7 changes: 6 additions & 1 deletion dvc/fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ def get_fs_cls(remote_conf):
def get_fs_config(config, **kwargs):
name = kwargs.get("name")
if name:
remote_conf = config["remote"][name.lower()]
try:
remote_conf = config["remote"][name.lower()]
except KeyError:
from dvc.config import RemoteNotFoundError

raise RemoteNotFoundError(f"remote '{name}' doesn't exist")
else:
remote_conf = kwargs
return _resolve_remote_refs(config, remote_conf)
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/fs/test_fs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from dvc.fs import get_fs_cls
from dvc.config import RemoteNotFoundError
from dvc.fs import get_fs_cls, get_fs_config
from dvc.fs.hdfs import HDFSFileSystem
from dvc.fs.http import HTTPFileSystem
from dvc.fs.https import HTTPSFileSystem
Expand Down Expand Up @@ -29,3 +30,8 @@
)
def test_get_fs_cls(url, cls):
assert get_fs_cls({"url": url}) == cls


def test_get_fs_config():
with pytest.raises(RemoteNotFoundError):
get_fs_config({"remote": {}}, name="myremote")

0 comments on commit 8d71c38

Please sign in to comment.