From a929cdd018635efa4f78ea659c363d4916158e5b Mon Sep 17 00:00:00 2001 From: Gunnar Andersson Date: Tue, 29 Oct 2024 19:51:11 +0100 Subject: [PATCH] Type checking constructor: error msg provids more info Signed-off-by: Gunnar Andersson --- ifex/model/type_checking_constructor_mixin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ifex/model/type_checking_constructor_mixin.py b/ifex/model/type_checking_constructor_mixin.py index 4bba815..5eff784 100644 --- a/ifex/model/type_checking_constructor_mixin.py +++ b/ifex/model/type_checking_constructor_mixin.py @@ -63,7 +63,11 @@ def type_checking_constructor(self, *args, **kwargs): for name, value in list(zip(arg_names, args)) + list(kwargs.items()): if not is_correct_type(value, arg_types[name]): - raise TypeError(f'Object construction error: According to specification, value named \'{name}\' must be of type: {arg_types[name]}, but was instead: {type(value)!r}.') + try: + nameinfo = f"Additional Info: The object was named: {self.name}" + except: + nameinfo = "" + raise TypeError(f'Object construction error for class {type(self)}: According to specification, value named \'{name}\' must be of type: {arg_types[name]}, but was instead: {type(value)!r}. {nameinfo}') # Assign field value setattr(self, name, value)