From fd192455f5838a8d36faa3e79d7c666ef847cf76 Mon Sep 17 00:00:00 2001 From: oop7 <110548351+oop7@users.noreply.github.com> Date: Sat, 17 Jan 2026 21:21:06 +0200 Subject: [PATCH] Handle Path objects in config JSON serialization Added a custom converter to serialize Path objects as strings when saving the application configuration to JSON. This prevents serialization errors if Path objects are present in the config. --- src/core/ytsage_utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/ytsage_utils.py b/src/core/ytsage_utils.py index 158acae..2e6c345 100644 --- a/src/core/ytsage_utils.py +++ b/src/core/ytsage_utils.py @@ -362,8 +362,14 @@ def load_config() -> Dict[str, Any]: def save_config(config: Dict[str, Any]) -> bool: """Save the application configuration to file.""" try: + # Convert any Path objects to strings for JSON serialization + def _convert_path(obj): + if isinstance(obj, Path): + return str(obj) + raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable") + with open(APP_CONFIG_FILE, "w", encoding="utf-8") as f: - json.dump(config, f, ensure_ascii=False, indent=2) + json.dump(config, f, ensure_ascii=False, indent=2, default=_convert_path) return True except Exception as e: logger.exception(f"Error saving config: {e}")