-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UserError exception type to separate server vs user errors
- Loading branch information
Showing
12 changed files
with
179 additions
and
45 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
bots/migrations/0054_savedrun_finish_reason_alter_savedrun_example_id_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.7 on 2023-12-30 00:52 | ||
|
||
from django.db import migrations, models | ||
from bots.models import FinishReason | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
saved_run = apps.get_model("bots", "SavedRun") | ||
saved_run.objects.filter(run_status="", error_msg="").update( | ||
finish_reason=FinishReason.DONE, | ||
) | ||
saved_run.objects.exclude(error_msg="").update( | ||
finish_reason=FinishReason.SERVER_ERROR, | ||
) | ||
|
||
|
||
def backwards_func(apps, schema_editor): | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("bots", "0053_alter_publishedrun_workflow_alter_savedrun_workflow_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="savedrun", | ||
name="finish_reason", | ||
field=models.IntegerField( | ||
choices=[(1, "User Error"), (2, "Server Error"), (3, "Done")], | ||
default=None, | ||
null=True, | ||
), | ||
), | ||
migrations.RunPython(forwards_func, backwards_func), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from contextlib import contextmanager | ||
from typing import Type | ||
|
||
|
||
class UserError(Exception): | ||
pass | ||
|
||
|
||
@contextmanager | ||
def raise_as_user_error(excs: list[Type[Exception]]): | ||
try: | ||
yield | ||
except tuple(excs) as e: | ||
raise UserError(str(e)) from e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.