Skip to content

Commit 6492120

Browse files
KIRA009abrichr
andauthored
feat(alerts): Alert user when any exception occurs, via sentry hooks (#685)
* feat: Alert user when any exception occurs, via sentry hooks * chore: Turn ERROR_REPORTING_BRANCH to a static config variable --------- Co-authored-by: Richard Abrich <[email protected]>
1 parent eff7152 commit 6492120

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

openadapt/config.defaults.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
"CACHE_VERBOSITY": 0,
1313
"DB_ECHO": false,
1414
"ERROR_REPORTING_ENABLED": true,
15-
"ERROR_REPORTING_DSN": "https://[email protected]/3798",
16-
"ERROR_REPORTING_BRANCH": "main",
1715
"OPENAI_MODEL_NAME": "gpt-3.5-turbo",
1816
"RECORD_WINDOW_DATA": false,
1917
"RECORD_READ_ACTIVE_ELEMENT_STATE": false,

openadapt/config.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import os
99
import pathlib
1010
import shutil
11+
import webbrowser
1112

1213
from loguru import logger
1314
from pydantic import field_validator
1415
from pydantic.fields import FieldInfo
1516
from pydantic_settings import BaseSettings, PydanticBaseSettingsSource
17+
from PySide6.QtWidgets import QMessageBox, QPushButton
1618
import git
1719
import sentry_sdk
1820

@@ -125,10 +127,10 @@ class SegmentationAdapter(str, Enum):
125127

126128
# Error reporting
127129
ERROR_REPORTING_ENABLED: bool = True
128-
ERROR_REPORTING_DSN: str = (
130+
ERROR_REPORTING_DSN: ClassVar = (
129131
"https://[email protected]/3798"
130132
)
131-
ERROR_REPORTING_BRANCH: str = "main"
133+
ERROR_REPORTING_BRANCH: ClassVar = "main"
132134

133135
# OpenAI
134136
OPENAI_MODEL_NAME: str = "gpt-3.5-turbo"
@@ -412,7 +414,34 @@ def print_config() -> None:
412414
)
413415
logger.info(f"{is_reporting_branch=}")
414416
if is_reporting_branch:
417+
418+
def show_alert() -> None:
419+
"""Show an alert to the user."""
420+
msg = QMessageBox()
421+
msg.setIcon(QMessageBox.Warning)
422+
msg.setText("""
423+
An error has occurred. The development team has been notified.
424+
Please join the discord server to get help or send an email to
425+
426+
""")
427+
discord_button = QPushButton("Join the discord server")
428+
discord_button.clicked.connect(
429+
lambda: webbrowser.open("https://discord.gg/yF527cQbDG")
430+
)
431+
msg.addButton(discord_button, QMessageBox.ActionRole)
432+
msg.addButton(QMessageBox.Ok)
433+
msg.exec()
434+
435+
def before_send_event(event: Any, hint: Any) -> Any:
436+
"""Handle the event before sending it to Sentry."""
437+
try:
438+
show_alert()
439+
except Exception:
440+
pass
441+
return event
442+
415443
sentry_sdk.init(
416444
dsn=config.ERROR_REPORTING_DSN,
417445
traces_sample_rate=1.0,
446+
before_send=before_send_event,
418447
)

0 commit comments

Comments
 (0)