Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use custom exceptions instead of KeyboardInterrupts and exit() #45

Merged
merged 3 commits into from
Aug 4, 2023

Conversation

swinglejohn
Copy link
Contributor

@swinglejohn swinglejohn commented Aug 2, 2023

Don't raise KeyboardInterrupts. Also raise exceptions instead of exit() so we can print the final cost.

@@ -137,7 +134,7 @@ def _set_file_paths(
cprint("The following paths do not exist:")
print("\n".join(invalid_paths))
print("Exiting...")
exit()
raise UserError()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the error to be the following paths don't exist instead of cprinting, and maybe get rid of the 'exiting...'? Since that should be standard (either always have it, or always don't have it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out the warning for bad file paths got broken when we switched to globbing so I moved this chunk of code to expand_paths() in app.py.

@@ -249,7 +246,7 @@ def _get_new_code_lines(self, changes) -> Iterable[str]:
min_changed_line = largest_changed_line + 1
for i, change in enumerate(changes):
if change.last_changed_line >= min_changed_line:
raise ValueError(f"Change line number overlap in file {change.file}")
raise UserError(f"Change line number overlap in file {change.file}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a MentatError; the collision handling is supposed to handle this

@@ -24,12 +25,10 @@ def setup_api_key():
openai.api_key = key
openai.Model.list() # Test the API key
except openai.error.AuthenticationError:
cprint(
raise UserError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call this function before the try except in app.py; we should move that call into loop() so this error gets properly caught

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

Copy link
Member

@PCSwingle PCSwingle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🪨

@PCSwingle PCSwingle merged commit 77c2bd0 into main Aug 4, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants