Replaced some fatal errors with custom exceptions

This commit is contained in:
Cyprian Laskowski 2021-11-03 22:25:28 +01:00
parent 8845cce2f4
commit d3c3c18d9e

View File

@ -230,6 +230,9 @@ class Msd:
return isinstance(obj, Msd) and self.code == obj.code and self.language == obj.language
class ConverterException(Exception):
pass
class Converter:
"""Converter between Msd and Properties objects."""
@ -254,7 +257,7 @@ class Converter:
"""Convert Msd to Properties (possibly in the other 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()
value_chars = msd.code[1:]
@ -270,8 +273,8 @@ class Converter:
feature_name = feature.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]):
exit('[ERROR] lemma is None but feature level depends on lemma for category={category}, position={position}'\
.format(category=category_name, position=index))
raise ConverterException('The lemma is None but feature level depends on lemma for category={category}, position={position}'\
.format(category=category_name, position=index))
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
feature_value_list.append((feature, value))