From 59899f0c624d76f778c4097100ffb47eaec981b8 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 29 Dec 2024 11:27:53 +0200 Subject: [PATCH] fix: improve patch generation error handling and logging --- pr_agent/algo/utils.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 2f2c10d7..9b49c060 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -583,27 +583,20 @@ def load_large_diff(filename, new_file_content_str: str, original_file_content_s """ Generate a patch for a modified file by comparing the original content of the file with the new content provided as input. - - Args: - new_file_content_str: The new content of the file as a string. - original_file_content_str: The original content of the file as a string. - - Returns: - The generated or provided patch string. - - Raises: - None. """ - patch = "" + if not original_file_content_str and not new_file_content_str: + return "" + try: diff = difflib.unified_diff(original_file_content_str.splitlines(keepends=True), new_file_content_str.splitlines(keepends=True)) if get_settings().config.verbosity_level >= 2 and show_warning: - get_logger().warning(f"File was modified, but no patch was found. Manually creating patch: {filename}.") + get_logger().info(f"File was modified, but no patch was found. Manually creating patch: {filename}.") patch = ''.join(diff) - except Exception: - pass - return patch + return patch + except Exception as e: + get_logger().exception(f"Failed to generate patch for file: {filename}") + return "" def update_settings_from_args(args: List[str]) -> List[str]: