exceptions.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. """Custom Exceptions."""
  2. class ReflexError(Exception):
  3. """Base exception for all Reflex exceptions."""
  4. class ConfigError(ReflexError):
  5. """Custom exception for config related errors."""
  6. class InvalidStateManagerMode(ReflexError, ValueError):
  7. """Raised when an invalid state manager mode is provided."""
  8. class ReflexRuntimeError(ReflexError, RuntimeError):
  9. """Custom RuntimeError for Reflex."""
  10. class UploadTypeError(ReflexError, TypeError):
  11. """Custom TypeError for upload related errors."""
  12. class EnvVarValueError(ReflexError, ValueError):
  13. """Custom ValueError raised when unable to convert env var to expected type."""
  14. class ComponentTypeError(ReflexError, TypeError):
  15. """Custom TypeError for component related errors."""
  16. class EventHandlerTypeError(ReflexError, TypeError):
  17. """Custom TypeError for event handler related errors."""
  18. class EventHandlerValueError(ReflexError, ValueError):
  19. """Custom ValueError for event handler related errors."""
  20. class StateValueError(ReflexError, ValueError):
  21. """Custom ValueError for state related errors."""
  22. class VarNameError(ReflexError, NameError):
  23. """Custom NameError for when a state var has been shadowed by a substate var."""
  24. class VarTypeError(ReflexError, TypeError):
  25. """Custom TypeError for var related errors."""
  26. class VarValueError(ReflexError, ValueError):
  27. """Custom ValueError for var related errors."""
  28. class VarAttributeError(ReflexError, AttributeError):
  29. """Custom AttributeError for var related errors."""
  30. class UploadValueError(ReflexError, ValueError):
  31. """Custom ValueError for upload related errors."""
  32. class RouteValueError(ReflexError, ValueError):
  33. """Custom ValueError for route related errors."""
  34. class VarOperationTypeError(ReflexError, TypeError):
  35. """Custom TypeError for when unsupported operations are performed on vars."""
  36. class VarDependencyError(ReflexError, ValueError):
  37. """Custom ValueError for when a var depends on a non-existent var."""
  38. class InvalidStylePropError(ReflexError, TypeError):
  39. """Custom Type Error when style props have invalid values."""
  40. class ImmutableStateError(ReflexError):
  41. """Raised when a background task attempts to modify state outside of context."""
  42. class LockExpiredError(ReflexError):
  43. """Raised when the state lock expires while an event is being processed."""
  44. class MatchTypeError(ReflexError, TypeError):
  45. """Raised when the return types of match cases are different."""
  46. class EventHandlerArgMismatch(ReflexError, TypeError):
  47. """Raised when the number of args accepted by an EventHandler differs from that provided by the event trigger."""
  48. class EventHandlerArgTypeMismatch(ReflexError, TypeError):
  49. """Raised when the annotations of args accepted by an EventHandler differs from the spec of the event trigger."""
  50. class EventFnArgMismatch(ReflexError, TypeError):
  51. """Raised when the number of args accepted by a lambda differs from that provided by the event trigger."""
  52. class DynamicRouteArgShadowsStateVar(ReflexError, NameError):
  53. """Raised when a dynamic route arg shadows a state var."""
  54. class ComputedVarShadowsStateVar(ReflexError, NameError):
  55. """Raised when a computed var shadows a state var."""
  56. class ComputedVarShadowsBaseVars(ReflexError, NameError):
  57. """Raised when a computed var shadows a base var."""
  58. class EventHandlerShadowsBuiltInStateMethod(ReflexError, NameError):
  59. """Raised when an event handler shadows a built-in state method."""
  60. class GeneratedCodeHasNoFunctionDefs(ReflexError):
  61. """Raised when refactored code generated with flexgen has no functions defined."""
  62. class PrimitiveUnserializableToJSON(ReflexError, ValueError):
  63. """Raised when a primitive type is unserializable to JSON. Usually with NaN and Infinity."""
  64. class InvalidLifespanTaskType(ReflexError, TypeError):
  65. """Raised when an invalid task type is registered as a lifespan task."""
  66. class DynamicComponentMissingLibrary(ReflexError, ValueError):
  67. """Raised when a dynamic component is missing a library."""
  68. class SetUndefinedStateVarError(ReflexError, AttributeError):
  69. """Raised when setting the value of a var without first declaring it."""
  70. class StateSchemaMismatchError(ReflexError, TypeError):
  71. """Raised when the serialized schema of a state class does not match the current schema."""
  72. class EnvironmentVarValueError(ReflexError, ValueError):
  73. """Raised when an environment variable is set to an invalid value."""
  74. class DynamicComponentInvalidSignature(ReflexError, TypeError):
  75. """Raised when a dynamic component has an invalid signature."""
  76. class InvalidPropValueError(ReflexError):
  77. """Raised when a prop value is invalid."""