1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add sentry_wrap decorator

This commit is contained in:
Steffo 2020-04-11 00:41:39 +02:00
parent 0e42273e6f
commit a4a263f142
2 changed files with 16 additions and 1 deletions

View file

@ -3,7 +3,7 @@ from .sleep_until import sleep_until
from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat from .formatters import andformat, underscorize, ytdldateformat, numberemojiformat, ordinalformat
from .urluuid import to_urluuid, from_urluuid from .urluuid import to_urluuid, from_urluuid
from .multilock import MultiLock from .multilock import MultiLock
from .sentry import init_sentry, sentry_exc from .sentry import init_sentry, sentry_exc, sentry_wrap
from .log import init_logging from .log import init_logging
from .royaltyping import JSON from .royaltyping import JSON
@ -20,6 +20,7 @@ __all__ = [
"MultiLock", "MultiLock",
"init_sentry", "init_sentry",
"sentry_exc", "sentry_exc",
"sentry_wrap",
"init_logging", "init_logging",
"JSON", "JSON",
] ]

View file

@ -3,6 +3,7 @@ import sys
import traceback import traceback
from typing import * from typing import *
from royalnet.version import semantic from royalnet.version import semantic
import functools
try: try:
import sentry_sdk import sentry_sdk
@ -45,3 +46,16 @@ def sentry_exc(exc: Exception,
if __debug__: if __debug__:
exc_type, exc_value, exc_traceback = sys.exc_info() exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback) traceback.print_exception(exc_type, exc_value, exc_traceback)
def sentry_wrap(level: str = "ERROR"):
def decorator(func: Callable):
@functools.wraps(func)
def new_func(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as exc:
sentry_exc(exc=exc, level=level)
raise
return new_func
return decorator