From 62eb4c0cb48f4769748230232802641974f8b5bb Mon Sep 17 00:00:00 2001 From: Jiri Podivin Date: Wed, 7 Apr 2021 15:16:48 +0200 Subject: [PATCH] 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 Change-Id: Iad8759410a922c17d8f05ab1d85b41629ec4b800 --- validations_common/validation.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/validations_common/validation.py b/validations_common/validation.py index 5323ce8..0a3dfe0 100755 --- a/validations_common/validation.py +++ b/validations_common/validation.py @@ -176,7 +176,12 @@ class Validation(argparse.ArgumentParser): t.add_row(r) print(t) 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): """Write output log file as Json format""" @@ -198,9 +203,9 @@ class Validation(argparse.ArgumentParser): if extra_vars: try: 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." - raise RuntimeError(msg) + raise RuntimeError(msg) from error v_actions = ValidationActions(validation_path=validation_dir, group=group) if 'run' in action: