
* test_component: improve valid/invalid event trigger tests Add test cases for event triggers defined as annotations. Add additional cases around lambda returning different values. Improve assertions for invalid tests (each line needs its own `pytest.raises`). More invalid test cases. * [REF-3589] raise EventHandlerArgMismatch when event handler args don't match spec Improve error message for common issue. Previously when the event handler arguments didn't match the spec, the traceback resulted in: ``` OSError: could not get source code ``` Now this problem is traceable as a distinct error condition and users are empowered to debug their code and reference the documentation (to be updated) for further information. * raise EventFnArgMismatch when lambda args don't match event trigger spec Improve error message for another common issue encountered in the reflex framework. Previous error message was ``` TypeError: index.<locals>.<lambda>() takes 0 positional arguments but 1 was given ``` * Fix up lambda test cases * call_event_fn: adjust number of args for bound methods
90 lines
2.6 KiB
Python
90 lines
2.6 KiB
Python
"""Custom Exceptions."""
|
|
|
|
|
|
class ReflexError(Exception):
|
|
"""Base exception for all Reflex exceptions."""
|
|
|
|
|
|
class ReflexRuntimeError(ReflexError, RuntimeError):
|
|
"""Custom RuntimeError for Reflex."""
|
|
|
|
|
|
class UploadTypeError(ReflexError, TypeError):
|
|
"""Custom TypeError for upload related errors."""
|
|
|
|
|
|
class EnvVarValueError(ReflexError, ValueError):
|
|
"""Custom ValueError raised when unable to convert env var to expected type."""
|
|
|
|
|
|
class ComponentTypeError(ReflexError, TypeError):
|
|
"""Custom TypeError for component related errors."""
|
|
|
|
|
|
class EventHandlerTypeError(ReflexError, TypeError):
|
|
"""Custom TypeError for event handler related errors."""
|
|
|
|
|
|
class EventHandlerValueError(ReflexError, ValueError):
|
|
"""Custom ValueError for event handler related errors."""
|
|
|
|
|
|
class StateValueError(ReflexError, ValueError):
|
|
"""Custom ValueError for state related errors."""
|
|
|
|
|
|
class VarNameError(ReflexError, NameError):
|
|
"""Custom NameError for when a state var has been shadowed by a substate var."""
|
|
|
|
|
|
class VarTypeError(ReflexError, TypeError):
|
|
"""Custom TypeError for var related errors."""
|
|
|
|
|
|
class VarValueError(ReflexError, ValueError):
|
|
"""Custom ValueError for var related errors."""
|
|
|
|
|
|
class VarAttributeError(ReflexError, AttributeError):
|
|
"""Custom AttributeError for var related errors."""
|
|
|
|
|
|
class UploadValueError(ReflexError, ValueError):
|
|
"""Custom ValueError for upload related errors."""
|
|
|
|
|
|
class RouteValueError(ReflexError, ValueError):
|
|
"""Custom ValueError for route related errors."""
|
|
|
|
|
|
class VarOperationTypeError(ReflexError, TypeError):
|
|
"""Custom TypeError for when unsupported operations are performed on vars."""
|
|
|
|
|
|
class VarDependencyError(ReflexError, ValueError):
|
|
"""Custom ValueError for when a var depends on a non-existent var."""
|
|
|
|
|
|
class InvalidStylePropError(ReflexError, TypeError):
|
|
"""Custom Type Error when style props have invalid values."""
|
|
|
|
|
|
class ImmutableStateError(ReflexError):
|
|
"""Raised when a background task attempts to modify state outside of context."""
|
|
|
|
|
|
class LockExpiredError(ReflexError):
|
|
"""Raised when the state lock expires while an event is being processed."""
|
|
|
|
|
|
class MatchTypeError(ReflexError, TypeError):
|
|
"""Raised when the return types of match cases are different."""
|
|
|
|
|
|
class EventHandlerArgMismatch(ReflexError, TypeError):
|
|
"""Raised when the number of args accepted by an EventHandler is differs from that provided by the event trigger."""
|
|
|
|
|
|
class EventFnArgMismatch(ReflexError, TypeError):
|
|
"""Raised when the number of args accepted by a lambda differs from that provided by the event trigger."""
|