diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-11-28 15:07:41 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-11-29 16:11:31 +0000 |
commit | 5ceb033caf279016876643315a66ab2aad3095d1 (patch) | |
tree | 98db2b546731c6cbe11ec312bc121baed87268af /morphlib/morphloader.py | |
parent | 5eafbe6c70910b5662c941f9f7a3c9befc61feea (diff) | |
download | morph-5ceb033caf279016876643315a66ab2aad3095d1.tar.gz |
morphloader: Don't use ValueError exception
Dedicated exceptions allow more fine-grained exception catching and can
have extra data.
Diffstat (limited to 'morphlib/morphloader.py')
-rw-r--r-- | morphlib/morphloader.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py index 702a330c..769d8c8e 100644 --- a/morphlib/morphloader.py +++ b/morphlib/morphloader.py @@ -92,6 +92,26 @@ class EmptyStratumError(morphlib.Error): (stratum_name, morphology)) +class DuplicateChunkError(morphlib.Error): + + def __init__(self, stratum_name, chunk_name): + self.stratum_name = stratum_name + self.chunk_name = chunk_name + morphlib.Error.__init__( + self, 'Duplicate chunk %(chunk_name)s '\ + 'in stratum %(stratum_name)s' % locals()) + + +class DuplicateStratumError(morphlib.Error): + + def __init__(self, system_name, stratum_name): + self.system_name = system_name + self.stratum_name = stratum_name + morphlib.Error.__init__( + self, 'Duplicate stratum %(stratum_name)s '\ + 'in system %(system_name)s' % locals()) + + class MorphologyLoader(object): '''Load morphologies from disk, or save them back to disk.''' @@ -255,7 +275,7 @@ class MorphologyLoader(object): for spec in morph['strata']: name = spec.get('alias', spec['morph']) if name in names: - raise ValueError('Duplicate stratum "%s"' % name) + raise DuplicateStratumError(morph['name'], name) names.add(name) # We allow the ARMv7 little-endian architecture to be specified @@ -277,7 +297,7 @@ class MorphologyLoader(object): for spec in morph['chunks']: name = spec.get('alias', spec['name']) if name in names: - raise ValueError('Duplicate chunk "%s"' % name) + raise DuplicateChunkError(morph['name'], name) names.add(name) # Require build-dependencies for the stratum itself, unless |