Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 96c70bcb609b143014ea1a630fdaf82bf79f0c01 Author: Michal Minar miminar@redhat.com Date: Thu Aug 29 08:20:34 2013 +0200
added 2 exceptions to clarify attribute access errors
When accessing not registered class from namespace or not existing part of namespace, an AttributeError was raised. Which is confusing. Now LMIClassNotFound or LMINamespaceNotFound raised instead with more descriptive information.
cli/lmi/shell/LMIExceptions.py | 18 ++++++++++++++++++ cli/lmi/shell/LMINamespace.py | 6 +++++- 2 files changed, 23 insertions(+), 1 deletions(-)
diff --git a/cli/lmi/shell/LMIExceptions.py b/cli/lmi/shell/LMIExceptions.py index e281207..d499918 100644 --- a/cli/lmi/shell/LMIExceptions.py +++ b/cli/lmi/shell/LMIExceptions.py @@ -68,3 +68,21 @@ class LMIFilterError(Exception): """ Raised, when there is a filter error present """ + +class LMIClassNotFound(AttributeError): + """ + Raised, when trying to access missing class in cim namespace. + """ + def __init__(self, namespace, class_name): + AttributeError.__init__(self, 'no such class "%s" in "%s" namespace' % + (class_name, namespace)) + +class LMINamespaceNotFound(AttributeError): + """ + Raised, when trying to access not existing namespace from connnection + or namespace object. + """ + def __init__(self, namespace, *args): + AttributeError.__init__(self, 'no such namespace "%s"' % + "/".join([namespace] + list(args))) + diff --git a/cli/lmi/shell/LMINamespace.py b/cli/lmi/shell/LMINamespace.py index e63cc29..67c496e 100644 --- a/cli/lmi/shell/LMINamespace.py +++ b/cli/lmi/shell/LMINamespace.py @@ -15,6 +15,8 @@
import sys
+import LMIExceptions + from LMIBaseObject import LMIWrapperBaseObject from LMIBaseClient import LMIBaseClient
@@ -49,7 +51,9 @@ class LMINamespace(LMIWrapperBaseObject): (class_list, _, _) = self._conn._client._get_class_names(self._name, DeepInheritance=True) if name in class_list: return lmi_wrap_cim_class(self._conn, name, self.name) - raise AttributeError(name) + if '_' in name: + raise LMIExceptions.LMIClassNotFound(self.name, name) + raise LMIExceptions.LMINamespaceNotFound(self.name, name)
def __repr__(self): """
cura-tools-devel@lists.fedorahosted.org