Преглед на файлове

Include var type in VarAttributeError message (#5118)

Khaleel Al-Adhami преди 1 месец
родител
ревизия
7a5e791fc4
променени са 2 файла, в които са добавени 3 реда и са изтрити 2 реда
  1. 1 1
      reflex/vars/base.py
  2. 2 1
      reflex/vars/object.py

+ 1 - 1
reflex/vars/base.py

@@ -1331,7 +1331,7 @@ class Var(Generic[VAR_TYPE]):
                 )
 
             raise VarAttributeError(
-                f"The State var has no attribute '{name}' or may have been annotated wrongly.",
+                f"The State var {escape(self._js_expr)} of type {escape(str(self._var_type))} has no attribute '{name}' or may have been annotated wrongly.",
             )
 
         def __bool__(self) -> bool:

+ 2 - 1
reflex/vars/object.py

@@ -17,6 +17,7 @@ from typing import (
     overload,
 )
 
+from rich.markup import escape
 from typing_extensions import is_typeddict
 
 from reflex.utils import types
@@ -326,7 +327,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
             attribute_type = get_attribute_access_type(var_type, name)
             if attribute_type is None:
                 raise VarAttributeError(
-                    f"The State var `{self!s}` has no attribute '{name}' or may have been annotated "
+                    f"The State var `{self!s}` of type {escape(str(self._var_type))} has no attribute '{name}' or may have been annotated "
                     f"wrongly."
                 )
             return ObjectItemOperation.create(self, name, attribute_type).guess_type()