Skip to content

Commit

Permalink
Use MalformedConfigFile exception when lang_map is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Sofia Margariti committed Nov 1, 2017
1 parent f72d49f commit ba3642e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 5 additions & 1 deletion txclib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import six

from txclib.exceptions import MalformedConfigFile


class OrderedRawConfigParser(configparser.RawConfigParser):
"""
Expand Down Expand Up @@ -67,7 +69,9 @@ def fromkeys(cls, keys, value=None):
def __setitem__(self, key, val):
k = self._flip.get(val, _NOTFOUND)
if not (k is _NOTFOUND or k == key):
raise KeyError('(key,val) would erase mapping for value %r' % val)
raise MalformedConfigFile("Your lang map configuration is not correct. "
"Duplicate entry detected with value '%s'. "
"Keys and values should be unique." % val)

v = self.get(key, _NOTFOUND)
if v is not _NOTFOUND:
Expand Down
14 changes: 6 additions & 8 deletions txclib/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ def get_resource_lang_mapping(self, resource):
lang_map.update({k: v})
except configparser.NoOptionError:
pass
except (ValueError, KeyError):
raise Exception(
"Your lang map configuration is not correct."
"Check that there are no duplicate keys or values.")
except ValueError:
raise MalformedConfigFile(
"Your lang map configuration is not correct.")

if self.config.has_section(resource):
res_lang_map = Flipdict()
Expand All @@ -313,10 +312,9 @@ def get_resource_lang_mapping(self, resource):
res_lang_map.update({k: v})
except configparser.NoOptionError:
pass
except (ValueError, KeyError):
raise Exception(
"Your lang map configuration is not correct."
"Check that there are no duplicate keys or values.")
except ValueError:
raise MalformedConfigFile(
"Your lang map configuration is not correct.")

# merge the lang maps and return result
lang_map.update(res_lang_map)
Expand Down

0 comments on commit ba3642e

Please sign in to comment.