URL: https://github.com/freeipa/freeipa/pull/880 Author: felipevolpone Title: #880: Changing how commands handles error when it can't connect to IPA server Action: opened
PR body: """ The commands that connects with IPA server can raise a `NetworkError` with the message: "ipa: ERROR: can't connect to `http://localhost:8888/ipa/json': [Errno 111] Connection refused`. Instead of that, this changes the message error in order to be more user-friendly. I've used the `GenericError` because it inherits from `PublicError`and do not have a default message. So, I do not have to change the `run` method in `ipalib/cli.py` to handle a different exception/case. Ticket: https://pagure.io/freeipa/issue/6261 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/880/head:pr880 git checkout pr880
From 1f9081e1e28176f8de82b866b0fab52282e7a2c4 Mon Sep 17 00:00:00 2001 From: Felipe Volpone <felipevolp...@gmail.com> Date: Mon, 19 Jun 2017 13:28:45 -0300 Subject: [PATCH] Changing how commands handles error when it can't connect to IPA server The commands that connects with IPA server can raise a NetworkError with the message: "ipa: ERROR: can't connect to 'http://localhost:8888/ipa/json': [Errno 111] Connection refused", which is not user friendly. Instead of that, this changes the message error in order to be more user-friendly. https://pagure.io/freeipa/issue/6261 --- ipalib/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 16f90c3bb2..692848a4a3 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -923,7 +923,7 @@ def _enable_warnings(error=False): from ipalib.parameters import DefaultFrom, Bool, Flag, Int, Decimal, Bytes, Str, IA5Str, Password, DNParam from ipalib.parameters import (BytesEnum, StrEnum, IntEnum, AccessTime, File, DateTime, DNSNameParam) -from ipalib.errors import SkipPluginModule +from ipalib.errors import SkipPluginModule, GenericError, NetworkError from ipalib.text import _, ngettext, GettextFactory, NGettextFactory Registry = plugable.Registry @@ -942,12 +942,17 @@ def packages(self): ipaserver.plugins, ) else: - import ipaclient.remote_plugins - import ipaclient.plugins - result = ( - ipaclient.remote_plugins.get_package(self), - ipaclient.plugins, - ) + try: + import ipaclient.remote_plugins + import ipaclient.plugins + result = ( + ipaclient.remote_plugins.get_package(self), + ipaclient.plugins, + ) + except NetworkError: + # instead of raising the default error connection message, + # raising a more user-friendly one + raise GenericError('Cannot find IPA server to contact') if self.env.context in ('installer', 'updates'): # pylint: disable=import-error,ipa-forbidden-import
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org