Skip to content

Commit

Permalink
Improve an error handling to debug this error: commit_changes_to_remo…
Browse files Browse the repository at this point in the history
…te_branch encountered an HTTPError: 409 Client Error: Conflict for url
  • Loading branch information
hiroshinishio committed Jul 8, 2024
1 parent ca7514f commit f80047e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion services/github/github_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 4 additions & 2 deletions utils/handle_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ 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)

# 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)
Expand All @@ -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)
Expand Down

0 comments on commit f80047e

Please sign in to comment.