From bff12ed930a821d5ef988d73173e665f42798755 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 31 Dec 2019 12:15:05 +0100 Subject: [PATCH] ++ exception handling --- scripts/uncloud | 3 +++ uncloud/__init__.py | 2 ++ uncloud/common/etcd_wrapper.py | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/uncloud b/scripts/uncloud index d22c6d0..4625164 100755 --- a/scripts/uncloud +++ b/scripts/uncloud @@ -8,6 +8,7 @@ import sys from logging.handlers import SysLogHandler from uncloud.configure.main import configure_parser +from uncloud import UncloudException def exception_hook(exc_type, exc_value, exc_traceback): logging.getLogger(__name__).error( @@ -61,5 +62,7 @@ if __name__ == '__main__': mod = importlib.import_module("uncloud.{}.main".format(name)) main = getattr(mod, "main") main(**arguments) + except UncloudException as err: + logger.error(err) except Exception as err: logger.exception(err) diff --git a/uncloud/__init__.py b/uncloud/__init__.py index e69de29..2920f47 100644 --- a/uncloud/__init__.py +++ b/uncloud/__init__.py @@ -0,0 +1,2 @@ +class UncloudException(Exception): + pass diff --git a/uncloud/common/etcd_wrapper.py b/uncloud/common/etcd_wrapper.py index 7367a6c..6a979ba 100644 --- a/uncloud/common/etcd_wrapper.py +++ b/uncloud/common/etcd_wrapper.py @@ -2,6 +2,7 @@ import etcd3 import json import queue import copy +from uncloud import UncloudException from collections import namedtuple from functools import wraps @@ -29,9 +30,9 @@ def readable_errors(func): try: return func(*args, **kwargs) except etcd3.exceptions.ConnectionFailedError as err: - raise etcd3.exceptions.ConnectionFailedError( - "etcd connection failed." - ) from err + raise UncloudException( + "Cannot connect to etcd: is etcd running as configured in uncloud.conf?" + ) except etcd3.exceptions.ConnectionTimeoutError as err: raise etcd3.exceptions.ConnectionTimeoutError( "etcd connection timeout."