From b2b227391a8a30bc70ae6f40214d6e697ccb51cd Mon Sep 17 00:00:00 2001 From: Stitch-z <284618289@qq.com> Date: Thu, 7 Sep 2023 20:08:02 +0800 Subject: [PATCH 1/2] update: Add exception handling for write file operation. --- metagpt/utils/file.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/metagpt/utils/file.py b/metagpt/utils/file.py index 93e1ad6c7..3e2adcf7b 100644 --- a/metagpt/utils/file.py +++ b/metagpt/utils/file.py @@ -27,9 +27,13 @@ class File: Returns: The full filename of file, such as "/data/test.txt". """ - root_path.mkdir(parents=True, exist_ok=True) - full_path = root_path / filename - async with aiofiles.open(full_path, mode="wb") as writer: - await writer.write(content) - logger.info(f"Successfully write docx: {full_path}") - return full_path \ No newline at end of file + try: + root_path.mkdir(parents=True, exist_ok=True) + full_path = root_path / filename + async with aiofiles.open(full_path, mode="wb") as writer: + await writer.write(content) + logger.info(f"Successfully write docx: {full_path}") + return full_path + except Exception as e: + logger.error(f"Error writing file: {e}") + raise e \ No newline at end of file From 5405d9cf32e79f3408a25d481940fe39e8c6316e Mon Sep 17 00:00:00 2001 From: Stitch-z <284618289@qq.com> Date: Thu, 7 Sep 2023 20:09:04 +0800 Subject: [PATCH 2/2] update: Add exception handling for write file operation. --- metagpt/utils/file.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metagpt/utils/file.py b/metagpt/utils/file.py index 3e2adcf7b..84b2f8aeb 100644 --- a/metagpt/utils/file.py +++ b/metagpt/utils/file.py @@ -26,6 +26,9 @@ class File: Returns: The full filename of file, such as "/data/test.txt". + + Raises: + Exception: If an unexpected error occurs during the file writing process. """ try: root_path.mkdir(parents=True, exist_ok=True)