From e6c5563a1665f1757b2000e9861808b116a109c2 Mon Sep 17 00:00:00 2001 From: Darko Poljak Date: Thu, 2 Nov 2017 13:57:36 +0100 Subject: [PATCH] NoSuchTypeError -> InvalidTypeError --- cdist/core/__init__.py | 2 +- cdist/core/cdist_type.py | 11 +++++++++-- cdist/emulator.py | 2 +- cdist/test/cdist_type/__init__.py | 2 +- cdist/test/config/__init__.py | 2 +- cdist/test/emulator/__init__.py | 4 ++-- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cdist/core/__init__.py b/cdist/core/__init__.py index 179c1a29..ebe69366 100644 --- a/cdist/core/__init__.py +++ b/cdist/core/__init__.py @@ -21,7 +21,7 @@ # from cdist.core.cdist_type import CdistType -from cdist.core.cdist_type import NoSuchTypeError +from cdist.core.cdist_type import NoSuchTypeError, InvalidTypeError from cdist.core.cdist_object import CdistObject from cdist.core.cdist_object import IllegalObjectIdError from cdist.core.explorer import Explorer diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py index 1f7c3eb5..b2b5e14d 100644 --- a/cdist/core/cdist_type.py +++ b/cdist/core/cdist_type.py @@ -32,10 +32,17 @@ class NoSuchTypeError(cdist.Error): self.type_absolute_path = type_absolute_path def __str__(self): - return "Type '%s' does not exist at %s" % ( + return "Type '%s' does not exist at '%s'" % ( self.type_path, self.type_absolute_path) +class InvalidTypeError(NoSuchTypeError): + def __str__(self): + return "Invalid type '%s' at '%s' defined at '%s'" % ( + self.type_path, self.type_absolute_path, + os.path.realpath(self.type_absolute_path)) + + class CdistType(object): """Represents a cdist type. @@ -51,7 +58,7 @@ class CdistType(object): self.path = self.name self.absolute_path = os.path.join(self.base_path, self.path) if not os.path.isdir(self.absolute_path): - raise NoSuchTypeError(self.name, self.path, self.absolute_path) + raise InvalidTypeError(self.name, self.path, self.absolute_path) self.manifest_path = os.path.join(self.name, "manifest") self.explorer_path = os.path.join(self.name, "explorer") self.gencode_local_path = os.path.join(self.name, "gencode-local") diff --git a/cdist/emulator.py b/cdist/emulator.py index 40b19e4b..0bb7ff16 100644 --- a/cdist/emulator.py +++ b/cdist/emulator.py @@ -247,7 +247,7 @@ class Emulator(object): # Raises an error, if object cannot be created try: cdist_object = self.cdist_object.object_from_name(requirement) - except core.cdist_type.NoSuchTypeError as e: + except core.cdist_type.InvalidTypeError as e: self.log.error(("%s requires object %s, but type %s does not" " exist. Defined at %s" % ( self.cdist_object.name, diff --git a/cdist/test/cdist_type/__init__.py b/cdist/test/cdist_type/__init__.py index 6e11383b..ca961170 100644 --- a/cdist/test/cdist_type/__init__.py +++ b/cdist/test/cdist_type/__init__.py @@ -55,7 +55,7 @@ class TypeTestCase(test.CdistTestCase): def test_nonexistent_type(self): base_path = fixtures - self.assertRaises(core.NoSuchTypeError, core.CdistType, base_path, + self.assertRaises(core.InvalidTypeError, core.CdistType, base_path, '__i-dont-exist') def test_name(self): diff --git a/cdist/test/config/__init__.py b/cdist/test/config/__init__.py index 5ff98269..252b7c8f 100644 --- a/cdist/test/config/__init__.py +++ b/cdist/test/config/__init__.py @@ -151,7 +151,7 @@ class ConfigRunTestCase(test.CdistTestCase): """Unknown type should be detected in the resolving process""" first = self.object_index['__first/man'] first.requirements = ['__nosuchtype/not/exist'] - with self.assertRaises(cdist.core.cdist_type.NoSuchTypeError): + with self.assertRaises(cdist.core.cdist_type.InvalidTypeError): self.config.iterate_until_finished() def test_requirement_singleton_where_no_singleton(self): diff --git a/cdist/test/emulator/__init__.py b/cdist/test/emulator/__init__.py index 6bc80e96..f94ce96d 100644 --- a/cdist/test/emulator/__init__.py +++ b/cdist/test/emulator/__init__.py @@ -76,14 +76,14 @@ class EmulatorTestCase(test.CdistTestCase): def test_nonexistent_type_exec(self): argv = ['__does-not-exist'] - self.assertRaises(core.cdist_type.NoSuchTypeError, emulator.Emulator, + self.assertRaises(core.cdist_type.InvalidTypeError, emulator.Emulator, argv, env=self.env) def test_nonexistent_type_requirement(self): argv = ['__file', '/tmp/foobar'] self.env['require'] = '__does-not-exist/some-id' emu = emulator.Emulator(argv, env=self.env) - self.assertRaises(core.cdist_type.NoSuchTypeError, emu.run) + self.assertRaises(core.cdist_type.InvalidTypeError, emu.run) def test_illegal_object_id_requirement(self): argv = ['__file', '/tmp/foobar']