From f80047ea574dcf4556e0f599668350a40098cbe8 Mon Sep 17 00:00:00 2001 From: Hiroshi Nishio <4620828+hiroshinishio@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:52:21 +0900 Subject: [PATCH] Improve an error handling to debug this error: commit_changes_to_remote_branch encountered an HTTPError: 409 Client Error: Conflict for url --- services/github/github_manager.py | 1 - utils/handle_exceptions.py | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/github/github_manager.py b/services/github/github_manager.py index 2502a0a6..eeb7b7c0 100644 --- a/services/github/github_manager.py +++ b/services/github/github_manager.py @@ -122,7 +122,6 @@ def commit_changes_to_remote_branch( ) original_text = "" sha = "" - print(f"{response.status_code=}\n") if response.status_code == 200: file_info: GitHubContentInfo = response.json() diff --git a/utils/handle_exceptions.py b/utils/handle_exceptions.py index eb49c2e6..80984130 100644 --- a/utils/handle_exceptions.py +++ b/utils/handle_exceptions.py @@ -36,7 +36,7 @@ def wrapper(*args: Tuple[Any, ...], **kwargs: Any): reset_ts = int(err.response.headers.get("X-RateLimit-Reset", 0)) current_ts = int(time.time()) wait_time = reset_ts - current_ts - err_msg = f"{func.__name__} encountered a GitHubPrimaryRateLimitError: {err}. Retrying after {wait_time} seconds. Limit: {limit}, Remaining: {remaining}, Used: {used}" + err_msg = f"{func.__name__} encountered a GitHubPrimaryRateLimitError: {err}. Retrying after {wait_time} seconds. Limit: {limit}, Remaining: {remaining}, Used: {used}. Reason: {reason}. Text: {text}" logging.error(msg=err_msg) time.sleep(wait_time + 5) # 5 seconds is a buffer return wrapper(*args, **kwargs) @@ -44,7 +44,7 @@ def wrapper(*args: Tuple[Any, ...], **kwargs: Any): # Check if the secondary rate limit has been exceeded if "exceeded a secondary rate limit" in err.response.text.lower(): retry_after = int(err.response.headers.get("Retry-After", 60)) - err_msg = f"{func.__name__} encountered a GitHubSecondaryRateLimitError: {err}. Retrying after {retry_after} seconds. Limit: {limit}, Remaining: {remaining}, Used: {used}" + err_msg = f"{func.__name__} encountered a GitHubSecondaryRateLimitError: {err}. Retrying after {retry_after} seconds. Limit: {limit}, Remaining: {remaining}, Used: {used}. Reason: {reason}. Text: {text}" logging.error(msg=err_msg) time.sleep(retry_after) return wrapper(*args, **kwargs) @@ -54,6 +54,8 @@ def wrapper(*args: Tuple[Any, ...], **kwargs: Any): logging.error(msg=err_msg) if raise_on_error: raise + + # Ex) 409: Conflict, and etc. else: err_msg = f"{func.__name__} encountered an HTTPError: {err}. Reason: {reason}. Text: {text}" logging.error(msg=err_msg)