Skip to content

Commit

Permalink
Type checking constructor: error msg provids more info
Browse files Browse the repository at this point in the history
Signed-off-by: Gunnar Andersson <[email protected]>
  • Loading branch information
gunnar-mb committed Nov 5, 2024
1 parent 369aa7d commit a929cdd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ifex/model/type_checking_constructor_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a929cdd

Please sign in to comment.