Add more error handling

This commit is contained in:
Andrew Godwin 2022-11-20 12:24:03 -07:00
parent facdd2c080
commit 77643a4fe1
7 changed files with 23 additions and 7 deletions

View file

@ -11,8 +11,8 @@
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
sodipodi:docname="icon-admin.svg"
inkscape:export-filename="icon-admin-512.png"
inkscape:export-xdpi="12.000001"
inkscape:export-ydpi="12.000001"
inkscape:export-xdpi="48.000004"
inkscape:export-ydpi="48.000004"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
@ -29,8 +29,8 @@
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="0.5946522"
inkscape:cx="761.78983"
inkscape:cy="461.61437"
inkscape:cx="765.99397"
inkscape:cy="467.50016"
inkscape:current-layer="layer1"><inkscape:grid
type="xygrid"
id="grid111" /></sodipodi:namedview><defs

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -4,6 +4,7 @@ import traceback
from typing import ClassVar, List, Optional, Type, Union, cast
from asgiref.sync import sync_to_async
from django.conf import settings
from django.db import models, transaction
from django.utils import timezone
from django.utils.functional import classproperty
@ -154,6 +155,10 @@ class StatorModel(models.Model):
next_state = await current_state.handler(self)
except BaseException as e:
await StatorError.acreate_from_instance(self, e)
if settings.SENTRY_ENABLED:
from sentry_sdk import capture_exception
capture_exception(e)
traceback.print_exc()
else:
if next_state:

View file

@ -5,6 +5,7 @@ import traceback
import uuid
from typing import List, Optional, Type
from django.conf import settings
from django.utils import timezone
from stator.models import StatorModel
@ -90,7 +91,11 @@ class StatorRunner:
f"Attempting transition on {instance._meta.label_lower}#{instance.pk} from state {instance.state}"
)
await instance.atransition_attempt()
except BaseException:
except BaseException as e:
if settings.SENTRY_ENABLED:
from sentry_sdk import capture_exception
capture_exception(e)
traceback.print_exc()
def remove_completed_tasks(self):

View file

@ -116,3 +116,5 @@ ALLOWED_HOSTS = ["*"]
AUTO_ADMIN_EMAIL: Optional[str] = None
STATOR_TOKEN: Optional[str] = None
SENTRY_ENABLED = False

View file

@ -91,3 +91,4 @@ if "SENTRY_DSN" in os.environ:
traces_sample_rate=1.0,
send_default_pii=True,
)
SENTRY_ENABLED = True

View file

@ -277,7 +277,7 @@ class Identity(StatorModel):
headers={"Accept": "application/json"},
follow_redirects=True,
)
except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
except httpx.RequestError:
return None, None
if response.status_code >= 400:
return None, None
@ -306,7 +306,7 @@ class Identity(StatorModel):
headers={"Accept": "application/json"},
follow_redirects=True,
)
except (httpx.ReadTimeout, httpx.ReadError, httpx.RemoteProtocolError):
except httpx.RequestError:
return False
if response.status_code >= 400:
return False

View file

@ -65,6 +65,9 @@ class InboxMessageStates(StateGraph):
f"Cannot handle activity of type undo.{unknown}"
)
case "delete":
# If there is no object type, it's probably a profile
if not isinstance(instance.message["object"], dict):
raise ValueError("Cannot handle activity of type delete")
match instance.message_object_type:
case "tombstone":
await sync_to_async(Post.handle_delete_ap)(instance.message)