From 8d71c3861fe9eb83e2e9d2ef0967662b56d57d71 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 2 Aug 2021 21:09:55 +0300 Subject: [PATCH] fs: raise RemoteNotFoundError (#6375) --- dvc/config.py | 10 +++++++++- dvc/fs/__init__.py | 7 ++++++- tests/unit/fs/test_fs.py | 8 +++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index a9d8b328d..98fe3086f 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -20,7 +20,15 @@ class ConfigError(DvcException): super().__init__(f"config file error: {msg}") -class NoRemoteError(ConfigError): +class RemoteConfigError(ConfigError): + pass + + +class NoRemoteError(RemoteConfigError): + pass + + +class RemoteNotFoundError(RemoteConfigError): pass diff --git a/dvc/fs/__init__.py b/dvc/fs/__init__.py index 117247d35..4aee14a9b 100644 --- a/dvc/fs/__init__.py +++ b/dvc/fs/__init__.py @@ -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) diff --git a/tests/unit/fs/test_fs.py b/tests/unit/fs/test_fs.py index 511486ed1..f1d82f064 100644 --- a/tests/unit/fs/test_fs.py +++ b/tests/unit/fs/test_fs.py @@ -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 @@ -29,3 +30,8 @@ from dvc.fs.ssh import SSHFileSystem ) 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")