Commit 75ee98ac authored by Bram Schoenmakers's avatar Bram Schoenmakers

Use raise ... from syntax to link exceptions

Python handles one exception at a time (per thread), raising a new
exception while still handling another one will result in run-time
errors. By linking the second exception to the original one, Python will
handle it correctly.

This was encountered while developing the alternative column UI, which
bailed out on completing a todo item with (invalid) child todo items.
parent 13b748ac
......@@ -71,8 +71,8 @@ class Command(object):
""" Retrieves a value from the argument list at the given position. """
try:
return self.args[p_number]
except IndexError:
raise InvalidCommandArgument
except IndexError as ie:
raise InvalidCommandArgument from ie
def getopt(self, p_flags, p_long=None):
p_long = p_long or []
......
......@@ -327,7 +327,7 @@ def config(p_path=None, p_overrides=None):
try:
config.instance = _Config(p_path, p_overrides)
except configparser.ParsingError as perr:
raise ConfigError(str(perr))
raise ConfigError(str(perr)) from perr
return config.instance
......
......@@ -95,11 +95,11 @@ class TodoListBase(object):
# the expression is a string and no leading zeroes,
# treat it as an integer
raise TypeError
except TypeError:
except TypeError as te:
try:
result = self._todos[int(p_identifier) - 1]
except (ValueError, IndexError):
raise InvalidTodoException
raise InvalidTodoException from te
return result
......@@ -249,8 +249,8 @@ class TodoListBase(object):
return self._todo_id_map[p_todo]
else:
return self._todos.index(p_todo) + 1
except (ValueError, KeyError):
raise InvalidTodoException
except (ValueError, KeyError) as ex:
raise InvalidTodoException from ex
def _update_todo_ids(self):
# the idea is to have a hash that is independent of the position of the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment