traitlets
traitlets copied to clipboard
Better insight on dictionary of traits instantiation
In the code, when an instance of traits dictionary is created, if an error occurs in a element construction, the original error message is not used. This makes it more complicated to figure out what went wrong.
https://github.com/ipython/traitlets/blob/32ced29b0ab06914ff92e9bdcd8806536633d701/traitlets/traitlets.py#L2835-L2845
It would be nice to add the catch error message to the newly created element error.
if key_trait:
try:
key = key_trait._validate(obj, key)
except TraitError as error:
- self.element_error(obj, key, key_trait, 'Keys')
+ self.element_error(obj, key, key_trait, str(error), 'Keys')
active_value_trait = per_key_override.get(key, value_trait)
if active_value_trait:
try:
v = active_value_trait._validate(obj, v)
except TraitError as error:
- self.element_error(obj, v, active_value_trait, 'Values')
+ self.element_error(obj, v, active_value_trait, str(error), 'Values')