Clarify KeyError() in Schedule.__init__()

If a YAML file contains an invalid recurrence the error is:
---
Invalid YAML meeting schedule definition - missing attribute 'weekly.'
< stack strace >
KeyError: 'weekly.'
---

This is quite right 'weekly.' isn't a missing attribute it's an invalid
recurrence type.  Refactor the code slightly to clarify the error message
---
Invalid meeting recurrence 'weekly.' - valid types: ['biweekly-odd', 'biweekly-even', 'weekly']
< stack strace >
KeyError: 'weekly.'
---

Change-Id: I8618bba454037744b82b5b96175d71ef8b2a652f
This commit is contained in:
Tony Breeds 2015-10-08 15:11:04 +11:00
parent 5b6e87c18e
commit c08530843c
1 changed files with 10 additions and 1 deletions

View File

@ -61,12 +61,21 @@ class Schedule(object):
self.day = sched_yaml['day'].lower().capitalize()
self.irc = sched_yaml['irc']
self.freq = sched_yaml['frequency']
self.recurrence = supported_recurrences[sched_yaml['frequency']]
self._recurrence = sched_yaml['frequency']
except KeyError as e:
print("Invalid YAML meeting schedule definition - missing "
"attribute '{0}'".format(e.args[0]))
raise
# Validate inputs
try:
self.recurrence = supported_recurrences[self._recurrence]
except KeyError as e:
print("Invalid meeting recurrence '{0}' - "
"valid types: {1}".format(e.args[0],
supported_recurrences.keys()))
raise
# optional: start_date defaults to the current date if not present
if 'start_date' in sched_yaml:
try: