Fixed exception handling of the print_tuple_table method.

KeyError was changed to IndexError
ValueError was changed to KeyError

Tuples don't have keys so the KeyError couldn't have
occured under any circumstances.

IndexError, on the other hand, can.

ValueError couldn't have been raised by the code.
KeyError is more appropriate in the context.

RuntimeError was replaced with more fitting TypeError.

Exceptions now indicate cause where applicable.

Raising exception with `from` sets the __cause__ attribute.

Error messages were expanded.

Signed-off-by: Jiri Podivin <jpodivin@redhat.com>
Change-Id: Iad8759410a922c17d8f05ab1d85b41629ec4b800
This commit is contained in:
Jiri Podivin 2021-04-07 15:16:48 +02:00
parent 3d6e5a1962
commit 62eb4c0cb4

View File

@ -176,7 +176,12 @@ class Validation(argparse.ArgumentParser):
t.add_row(r) t.add_row(r)
print(t) print(t)
else: else:
raise RuntimeError("Wrong data type.") raise TypeError(
(
"data must be of 'tuple' type. "
"Instead {} was provided."
).format(type(data))
)
def _write_output(self, output_log, results): def _write_output(self, output_log, results):
"""Write output log file as Json format""" """Write output log file as Json format"""
@ -198,9 +203,9 @@ class Validation(argparse.ArgumentParser):
if extra_vars: if extra_vars:
try: try:
extra_vars = dict(e.split("=") for e in parsed_args.extra_vars) extra_vars = dict(e.split("=") for e in parsed_args.extra_vars)
except ValueError: except ValueError as error:
msg = "extra vars option should be formed as: KEY=VALUE." msg = "extra vars option should be formed as: KEY=VALUE."
raise RuntimeError(msg) raise RuntimeError(msg) from error
v_actions = ValidationActions(validation_path=validation_dir, v_actions = ValidationActions(validation_path=validation_dir,
group=group) group=group)
if 'run' in action: if 'run' in action: