From 5ff3e0de7d1b652c7a6d0a3572ab7ac68fa639f1 Mon Sep 17 00:00:00 2001 From: seehi <6580@pm.me> Date: Tue, 27 Aug 2024 15:57:11 +0800 Subject: [PATCH] update comment --- metagpt/schema.py | 2 +- metagpt/utils/common.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/metagpt/schema.py b/metagpt/schema.py index 5f9a5667f..201ff4357 100644 --- a/metagpt/schema.py +++ b/metagpt/schema.py @@ -147,7 +147,7 @@ class SerializationMixin(BaseModel, extra="forbid"): serialized_data = self.model_dump() - write_json_file(file_path, serialized_data) + write_json_file(file_path, serialized_data, use_fallback=True) logger.debug(f"{self.__class__.__qualname__} serialization successful. File saved at: {file_path}") return file_path diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py index 2b2a209be..42a872c76 100644 --- a/metagpt/utils/common.py +++ b/metagpt/utils/common.py @@ -581,20 +581,20 @@ def read_json_file(json_file: str, encoding: str = "utf-8") -> list[Any]: def handle_unknown_serialization(x: Any) -> str: - """For `to_jsonable_python` debug, unknown values will be logged instead of raising an exception.""" + """For `to_jsonable_python` debug, get more detail about the x.""" if inspect.ismethod(x): - logger.error(f"Method: {x.__self__.__class__.__name__}.{x.__func__.__name__}") + tip = f"Cannot serialize method '{x.__func__.__name__}' of class '{x.__self__.__class__.__name__}'" elif inspect.isfunction(x): - logger.error(f"Function: {x.__name__}") + tip = f"Cannot serialize function '{x.__name__}'" elif hasattr(x, "__class__"): - logger.error(f"Instance of: {x.__class__.__name__}") + tip = f"Cannot serialize instance of '{x.__class__.__name__}'" elif hasattr(x, "__name__"): - logger.error(f"Class or module: {x.__name__}") + tip = f"Cannot serialize class or module '{x.__name__}'" else: - logger.error(f"Unknown type: {type(x)}") + tip = f"Cannot serialize object of type '{type(x).__name__}'" - return f"" + raise TypeError(tip) def write_json_file(json_file: str, data: Any, encoding: str = "utf-8", indent: int = 4, use_fallback: bool = False):