-
Notifications
You must be signed in to change notification settings - Fork 237
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
Conversation
mentat/code_file_manager.py
Outdated
@@ -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() |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
mentat/code_file_manager.py
Outdated
@@ -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}") |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🪨
Don't raise KeyboardInterrupts. Also raise exceptions instead of exit() so we can print the final cost.