From d51a177a9545f9d534c24c25239144a6f8bd4b3d Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 13 Feb 2012 16:22:14 +0100 Subject: [PATCH] invent a generic CdistObjectError and point to definition source (easier debugging) Signed-off-by: Nico Schottelius --- lib/cdist/__init__.py | 12 ++++++++++++ lib/cdist/resolver.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cdist/__init__.py b/lib/cdist/__init__.py index 973b61f8..4742a937 100644 --- a/lib/cdist/__init__.py +++ b/lib/cdist/__init__.py @@ -44,6 +44,18 @@ class Error(Exception): """Base exception class for this project""" pass +class CdistObjectError(Error): + """Something went wrong with an object""" + + def __init__(self, cdist_object, message): + self.name = cdist_object.name + self.source = " ".join(cdist_object.source) + self.message = message + + + def __str__(self): + return '%s: %s (defined at %s)' % (self.name, self.message, self.source) + def file_to_list(filename): """Return list from \n seperated file""" if os.path.isfile(filename): diff --git a/lib/cdist/resolver.py b/lib/cdist/resolver.py index 24a5e496..368c9eb8 100644 --- a/lib/cdist/resolver.py +++ b/lib/cdist/resolver.py @@ -125,7 +125,7 @@ class DependencyResolver(object): resolved.append(cdist_object) unresolved.remove(cdist_object) except RequirementNotFoundError as e: - raise cdist.Error(cdist_object.name + " requires non-existing " + e.requirement) + raise cdist.CdistObjectError(cdist_object, "requires non-existing " + e.requirement) def __iter__(self): """Iterate over all unique objects while resolving dependencies.