Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested exceptions from failed PrefixList validation. #955

Closed
mdickinson opened this issue Mar 23, 2020 · 0 comments · Fixed by #956 or #1564
Closed

Nested exceptions from failed PrefixList validation. #955

mdickinson opened this issue Mar 23, 2020 · 0 comments · Fixed by #956 or #1564

Comments

@mdickinson
Copy link
Member

mdickinson commented Mar 23, 2020

Failed assignments to PrefixList cause a nested exception: we raise a TraitError, catch that raised error, and then raise another TraitError. This suggests a logic error somewhere.

>>> from traits.api import *
>>> class A(HasTraits):
...     foo = PrefixList(["one", "two", "three"])
... 
>>> a = A()
>>> a.foo = "t"
Traceback (most recent call last):
  File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 2526, in validate
    self.error(object, name, value)
  File "/Users/mdickinson/Enthought/ETS/traits/traits/base_trait_handler.py", line 76, in error
    raise TraitError(
traits.trait_errors.TraitError: The 'foo' trait of an A instance must be 'one' or 'two' or 'three' (or any unique prefix), but a value of 't' <class 'str'> was specified.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Enthought/ETS/traits/traits/trait_types.py", line 2530, in validate
    self.error(object, name, value)
  File "/Users/mdickinson/Enthought/ETS/traits/traits/base_trait_handler.py", line 76, in error
    raise TraitError(
traits.trait_errors.TraitError: The 'foo' trait of an A instance must be 'one' or 'two' or 'three' (or any unique prefix), but a value of 't' <class 'str'> was specified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant