Repository: reflex-dev/reflex
Pull request: added name of Var to error message
-  Added the name of the Var to the error message for ```TypeError(f"No JSON serializer found for var {value} of type {type(value)}.")``` closes #2826 





### All Submissions:

- [x] Have you followed the guidelines stated in [CONTRIBUTING.md](https://github.com/reflex-dev/reflex/blob/main/CONTRIBUTING.md) file?
- [x] Have you checked to ensure there aren't any other open [Pull Requests](https://github.com/reflex-dev/reflex/pulls ) for the desired changed?

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### Type of change

Please delete options that are not relevant.

- [x] New feature (non-breaking change which adds functionality)




### New Feature Submission:

- [x] Does your submission pass the tests? 
- [x] Have you linted your code locally prior to submission?

### Changes To Core Features:

- [x] Have you added an explanation of what your changes do and why you'd like us to include them?
- [x] Have you successfully ran tests with your changes locally?

### **After** these steps, you're ready to open a pull request.

    a. Give a descriptive title to your PR.
        
    b. Describe your changes.

    c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).



Problem statement:
include the name of the Var so it's easier to track down `No JSON serializer` error
It will be nice to also include the name of the Var causing the ```TypeError(f"No JSON serializer found for var {value} of type {type(value)}.")```  so it's easier for a user to track down and maybe convert the Var to a string

Hints from issue discussion:

Commit message: added name of Var to error message

Patch to review:
diff --git a/reflex/utils/format.py b/reflex/utils/format.py
index 53b55d0ebdf..dd79be132d0 100644
--- a/reflex/utils/format.py
+++ b/reflex/utils/format.py
@@ -2,9 +2,11 @@
 
 from __future__ import annotations
 
+import functools
 import inspect
 import json
 import os
+import pathlib
 import re
 import sys
 from typing import TYPE_CHECKING, Any, List, Union
@@ -598,7 +600,14 @@ def format_state(value: Any) -> Any:
     """
     # Handle dicts.
     if isinstance(value, dict):
-        return {k: format_state(v) for k, v in value.items()}
+        result = {}
+        for k, v in value.items():
+            if isinstance(v, (pathlib.PosixPath, functools.partial)):
+                raise TypeError(
+                    f"No JSON serializer found for var {k} of value {v} of type {type(v)}."
+                )
+            result[k] = format_state(v)
+        return result
 
     # Handle lists, sets, typles.
     if isinstance(value, types.StateIterBases):


Code review comments:
diff_hunk: @@ -598,7 +600,14 @@ def format_state(value: Any) -> Any:
     """
     # Handle dicts.
     if isinstance(value, dict):
-        return {k: format_state(v) for k, v in value.items()}
+        result = {}
+        for k, v in value.items():
+            if isinstance(v, (pathlib.PosixPath, functools.partial)):
path: reflex/utils/format.py
text: @user1:
I think we can be more general here by either:
1. Using `reflex.utils.serailizers.has_serializer` to check
2. Just putting a try/except around the setting.

Actually I think the easiest fix would be to pass down the key to `format_state` and just update the error message thrown there.

@author:
Thanks, @user1, your suggestion makes sense. 

@author:
I have now updated the code by passing the key to `format_state` and updating the error message