From 2fb6b338bde64af85bec74f3ee0872da13845668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Fri, 24 Jan 2020 15:13:14 +0000 Subject: [PATCH] move message creation outside of exception --- dvc/config.py | 26 +------------------------- dvc/data_cloud.py | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index f2334495e..d2d60d68d 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -24,31 +24,7 @@ class ConfigError(DvcException): class NoRemoteError(ConfigError): - def __init__(self, command, *, config=None): - has_any_remote = False - if config: - has_any_remote = bool( - config.list_options( - Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL - ) - ) - - if has_any_remote: - msg = ( - "no remote specified. Setup default remote with\n" - " dvc remote default \n" - "or use:\n" - " dvc {} -r ".format(command) - ) - else: - msg = ( - "no remote specified. Create a remote with\n" - " dvc remote add \n" - "To create a default remote use the -d flag:\n" - " dvc remote add -d " - ) - - super().__init__(msg) + pass def supported_cache_type(types): diff --git a/dvc/data_cloud.py b/dvc/data_cloud.py index a989bf47a..9babe164a 100644 --- a/dvc/data_cloud.py +++ b/dvc/data_cloud.py @@ -39,7 +39,26 @@ class DataCloud(object): if remote: return self._init_remote(remote) - raise NoRemoteError(command, config=self.repo.config) + has_non_default_remote = bool( + self.repo.config.list_options( + Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL + ) + ) + + if has_non_default_remote: + error_msg = ( + "no remote specified. Setup default remote with\n" + " dvc remote default \n" + "or use:\n" + " dvc {} -r ".format(command) + ) + else: + error_msg = ( + "no remote specified. Create a default remote with\n" + " dvc remote add -d " + ) + + raise NoRemoteError(error_msg) def _init_remote(self, remote): return Remote(self.repo, name=remote)