From 0fd102c2f8cd023a21fcae1a8820daaad7e16622 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Wed, 12 Jul 2017 02:07:41 -0700 Subject: [PATCH 1/2] catch download failures better in init, re: #522 --- src/rosdep2/main.py | 9 +++++---- src/rosdep2/sources_list.py | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index b3e4a3da1..30baafc05 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -59,7 +59,7 @@ from . import create_default_installer_context, get_default_installer from . import __version__ -from .core import RosdepInternalError, InstallFailed, UnsupportedOs, InvalidData, CachePermissionError +from .core import RosdepInternalError, InstallFailed, UnsupportedOs, InvalidData, CachePermissionError, DownloadFailure from .installers import normalize_uninstalled_to_list from .installers import RosdepInstaller from .lookup import RosdepLookup, ResolutionError @@ -517,6 +517,10 @@ def command_init(options): except URLError as e: print("ERROR: cannot download default sources list from:\n%s\nWebsite may be down."%(DEFAULT_SOURCES_LIST_URL)) return 4 + except DownloadFailure as e: + print("ERROR: cannot download default sources list from:\n%s\nWebsite may be down."%(DEFAULT_SOURCES_LIST_URL)) + print(e) + return 4 # reuse path variable for error message path = get_sources_list_dir() old_umask = os.umask(0o022) @@ -878,6 +882,3 @@ def command_fix_permissions(options): _command_no_args = ['update', 'init', 'db', 'fix-permissions'] _commands = command_handlers.keys() - - - diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index c3ee03475..d5078c398 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -309,7 +309,8 @@ def download_default_sources_list(url=DEFAULT_SOURCES_LIST_URL): :param url: override URL of default sources list file :return: raw sources list data, ``str`` - :raises: :exc:`InvalidData` + :raises: :exc:`DownloadFailure` If data cannot be + retrieved (e.g. 404, bad YAML format, server down). :raises: :exc:`urllib2.URLError` If data cannot be retrieved (e.g. 404, server down). """ @@ -320,9 +321,12 @@ def download_default_sources_list(url=DEFAULT_SOURCES_LIST_URL): data = f.read().decode() f.close() if not data: - raise RuntimeError("cannot download defaults file: empty contents") + raise DownloadFailure("cannot download defaults file from %s : empty contents" % url) # parse just for validation - parse_sources_data(data) + try: + parse_sources_data(data) + except InvalidData as e: + raise DownloadFailure("Failed to download valid rosdep sources from %s Contents were:{{{%s}}} Parsing error: %s" % (url, data, e)) return data def parse_sources_data(data, origin='', model=None): From 1cd8b8520ca8e4bdc420bf32d2ff7ef01ecb07e2 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Fri, 28 Jul 2017 11:06:33 -0700 Subject: [PATCH 2/2] Making error message much more verbose. --- src/rosdep2/sources_list.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index d5078c398..c01d082b9 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -326,7 +326,9 @@ def download_default_sources_list(url=DEFAULT_SOURCES_LIST_URL): try: parse_sources_data(data) except InvalidData as e: - raise DownloadFailure("Failed to download valid rosdep sources from %s Contents were:{{{%s}}} Parsing error: %s" % (url, data, e)) + raise DownloadFailure("The content downloaded from %s failed to pass validation." + " It is likely that the source is invalid unless the data was corrupted during the download." + " The contents were:{{{%s}}} The error raised was: %s" % (url, data, e)) return data def parse_sources_data(data, origin='', model=None):