++ exception handling

This commit is contained in:
Nico Schottelius 2019-12-31 12:15:05 +01:00
parent 1fba79ca31
commit bff12ed930
3 changed files with 9 additions and 3 deletions

View file

@ -8,6 +8,7 @@ import sys
from logging.handlers import SysLogHandler from logging.handlers import SysLogHandler
from uncloud.configure.main import configure_parser from uncloud.configure.main import configure_parser
from uncloud import UncloudException
def exception_hook(exc_type, exc_value, exc_traceback): def exception_hook(exc_type, exc_value, exc_traceback):
logging.getLogger(__name__).error( logging.getLogger(__name__).error(
@ -61,5 +62,7 @@ if __name__ == '__main__':
mod = importlib.import_module("uncloud.{}.main".format(name)) mod = importlib.import_module("uncloud.{}.main".format(name))
main = getattr(mod, "main") main = getattr(mod, "main")
main(**arguments) main(**arguments)
except UncloudException as err:
logger.error(err)
except Exception as err: except Exception as err:
logger.exception(err) logger.exception(err)

View file

@ -0,0 +1,2 @@
class UncloudException(Exception):
pass

View file

@ -2,6 +2,7 @@ import etcd3
import json import json
import queue import queue
import copy import copy
from uncloud import UncloudException
from collections import namedtuple from collections import namedtuple
from functools import wraps from functools import wraps
@ -29,9 +30,9 @@ def readable_errors(func):
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except etcd3.exceptions.ConnectionFailedError as err: except etcd3.exceptions.ConnectionFailedError as err:
raise etcd3.exceptions.ConnectionFailedError( raise UncloudException(
"etcd connection failed." "Cannot connect to etcd: is etcd running as configured in uncloud.conf?"
) from err )
except etcd3.exceptions.ConnectionTimeoutError as err: except etcd3.exceptions.ConnectionTimeoutError as err:
raise etcd3.exceptions.ConnectionTimeoutError( raise etcd3.exceptions.ConnectionTimeoutError(
"etcd connection timeout." "etcd connection timeout."