From dd49f1f174b1b3fc2ae9ef3c05050d44d9ee1020 Mon Sep 17 00:00:00 2001 From: Juan Altmayer Pizzorno Date: Tue, 16 Apr 2024 11:16:29 -0400 Subject: [PATCH] - reviewed / cleaned up API exception handling; --- src/coverup/coverup.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/coverup/coverup.py b/src/coverup/coverup.py index a9d145c..03fcd3d 100644 --- a/src/coverup/coverup.py +++ b/src/coverup/coverup.py @@ -476,7 +476,9 @@ async def do_chat(seg: CodeSegment, completion: dict) -> str: return await litellm.acreate(**completion) - except (openai.RateLimitError, openai.APITimeoutError, litellm.APIError, litellm.exceptions.ServiceUnavailableError) as e: + except (litellm.exceptions.ServiceUnavailableError, + openai.RateLimitError, + openai.APITimeoutError) as e: # This message usually indicates out of money in account if 'You exceeded your current quota' in str(e): @@ -496,14 +498,17 @@ async def do_chat(seg: CodeSegment, completion: dict) -> str: log_write(seg, f"Error: {type(e)} {e}") return None # gives up this segment - except (ConnectionError) as e: + except openai.APIConnectionError as e: log_write(seg, f"Error: {type(e)} {e}") # usually a server-side error... just retry right away state.inc_counter('R') - except subprocess.CalledProcessError as e: - print(f"coverup: subprocess.CalledProcessError {e.returncode}: {str(e.stdout, 'UTF-8', errors='ignore')}") - + except openai.APIError as e: + # APIError is the base class for all API errors; + # we may be missing a more specific handler. + print(f"Error: {type(e)} {e}; missing handler?") + log_write(seg, f"Error: {type(e)} {e}") + return None # gives up this segment def extract_python(response: str) -> str: # This regex accepts a truncated code block... this seems fine since we'll try it anyway