瀏覽代碼

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(
             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:
         def __bool__(self) -> bool:

+ 2 - 1
reflex/vars/object.py

@@ -17,6 +17,7 @@ from typing import (
     overload,
     overload,
 )
 )
 
 
+from rich.markup import escape
 from typing_extensions import is_typeddict
 from typing_extensions import is_typeddict
 
 
 from reflex.utils import types
 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)
             attribute_type = get_attribute_access_type(var_type, name)
             if attribute_type is None:
             if attribute_type is None:
                 raise VarAttributeError(
                 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."
                     f"wrongly."
                 )
                 )
             return ObjectItemOperation.create(self, name, attribute_type).guess_type()
             return ObjectItemOperation.create(self, name, attribute_type).guess_type()