Replaced some fatal errors with custom exceptions
This commit is contained in:
parent
8845cce2f4
commit
d3c3c18d9e
|
@ -230,6 +230,9 @@ class Msd:
|
||||||
return isinstance(obj, Msd) and self.code == obj.code and self.language == obj.language
|
return isinstance(obj, Msd) and self.code == obj.code and self.language == obj.language
|
||||||
|
|
||||||
|
|
||||||
|
class ConverterException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class Converter:
|
class Converter:
|
||||||
"""Converter between Msd and Properties objects."""
|
"""Converter between Msd and Properties objects."""
|
||||||
|
|
||||||
|
@ -254,7 +257,7 @@ class Converter:
|
||||||
"""Convert Msd to Properties (possibly in the other language)."""
|
"""Convert Msd to Properties (possibly in the other language)."""
|
||||||
|
|
||||||
if (msd.code not in self.specifications.codes_map[msd.language]):
|
if (msd.code not in self.specifications.codes_map[msd.language]):
|
||||||
exit('[ERROR] msd {} is unknown'.format(msd.code))
|
raise ConverterException('The msd {} is unknown'.format(msd.code))
|
||||||
|
|
||||||
category_char = msd.code[0].lower()
|
category_char = msd.code[0].lower()
|
||||||
value_chars = msd.code[1:]
|
value_chars = msd.code[1:]
|
||||||
|
@ -270,7 +273,7 @@ class Converter:
|
||||||
feature_name = feature.names.get(language)
|
feature_name = feature.names.get(language)
|
||||||
feature_value = value.names.get(language)
|
feature_value = value.names.get(language)
|
||||||
if (lemma is None and (category_name, index) in [(le[0], le[1]) for le in LEVEL_EXCEPTIONS]):
|
if (lemma is None and (category_name, index) in [(le[0], le[1]) for le in LEVEL_EXCEPTIONS]):
|
||||||
exit('[ERROR] lemma is None but feature level depends on lemma for category={category}, position={position}'\
|
raise ConverterException('The lemma is None but feature level depends on lemma for category={category}, position={position}'\
|
||||||
.format(category=category_name, position=index))
|
.format(category=category_name, position=index))
|
||||||
level_exception_flag = (category_name, feature.position, lemma) in LEVEL_EXCEPTIONS
|
level_exception_flag = (category_name, feature.position, lemma) in LEVEL_EXCEPTIONS
|
||||||
lexeme_level_flag = feature.lexeme_level_flag if not level_exception_flag else not feature.lexeme_level_flag
|
lexeme_level_flag = feature.lexeme_level_flag if not level_exception_flag else not feature.lexeme_level_flag
|
||||||
|
|
Loading…
Reference in New Issue
Block a user