Skip to content

Commit 776f3cc

Browse files
author
Tjaz Erzen
committed
Handle broader set of errors
1 parent 1d19354 commit 776f3cc

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

codeplain_REST_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Optional
33

44
import requests
5-
from requests.exceptions import ConnectionError, RequestException, Timeout
65

76
import plain2code_exceptions
87
from plain2code_state import RunState

plain2code.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
from module_renderer import ModuleRenderer
1818
from plain2code_arguments import parse_arguments
1919
from plain2code_console import console
20-
from plain2code_exceptions import InternalServerError, InvalidFridArgument, MissingAPIKey, PlainSyntaxError
20+
from plain2code_exceptions import (
21+
ConflictingRequirements,
22+
CreditBalanceTooLow,
23+
InternalServerError,
24+
InvalidFridArgument,
25+
LLMInternalError,
26+
MissingAPIKey,
27+
MissingResource,
28+
PlainSyntaxError,
29+
UnexpectedState,
30+
)
2131
from plain2code_logger import (
2232
CrashLogHandler,
2333
IndentedFormatter,
@@ -205,7 +215,7 @@ def render(args, run_state: RunState, codeplain_api, event_bus: EventBus): # no
205215
return
206216

207217

208-
def main():
218+
def main(): # noqa: C901
209219
args = parse_arguments()
210220

211221
event_bus = EventBus()
@@ -253,12 +263,28 @@ def main():
253263
dump_crash_logs(args)
254264
except MissingAPIKey as e:
255265
console.error(f"Missing API key: {str(e)}\n")
256-
except InternalServerError:
266+
except (InternalServerError, UnexpectedState) as e:
257267
console.error(
258-
f"Internal server error.\n\nPlease report the error to support@codeplain.ai with the attached {args.log_file_name} file."
268+
f"Internal server error: {str(e)}.\n\nPlease report the error to support@codeplain.ai with the attached {args.log_file_name} file."
259269
)
260270
console.debug(f"Render ID: {run_state.render_id}")
261271
dump_crash_logs(args)
272+
except ConflictingRequirements as e:
273+
console.error(f"Conflicting requirements: {str(e)}\n")
274+
console.debug(f"Render ID: {run_state.render_id}")
275+
dump_crash_logs(args)
276+
except CreditBalanceTooLow as e:
277+
console.error(f"Credit balance too low: {str(e)}\n")
278+
console.debug(f"Render ID: {run_state.render_id}")
279+
dump_crash_logs(args)
280+
except LLMInternalError as e:
281+
console.error(f"LLM internal error: {str(e)}\n")
282+
console.debug(f"Render ID: {run_state.render_id}")
283+
dump_crash_logs(args)
284+
except MissingResource as e:
285+
console.error(f"Missing resource: {str(e)}\n")
286+
console.debug(f"Render ID: {run_state.render_id}")
287+
dump_crash_logs(args)
262288
except Exception as e:
263289
console.error(f"Error rendering plain code: {str(e)}\n")
264290
console.debug(f"Render ID: {run_state.render_id}")

0 commit comments

Comments
 (0)