Skip to content

Commit

Permalink
fix: errors not propagating in some situations
Browse files Browse the repository at this point in the history
BT-49
  • Loading branch information
Skelmis committed May 18, 2024
1 parent dcec7c0 commit d281c5b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
4 changes: 3 additions & 1 deletion suggestions/cogs/suggestion_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from suggestions.interaction_handler import InteractionHandler
from suggestions.objects import Suggestion, GuildConfig, QueuedSuggestion
from suggestions.objects.suggestion import SuggestionState
from suggestions.utility import r2
from suggestions.utility import r2, wrap_with_error_handler

if TYPE_CHECKING:
from alaric import Document
Expand Down Expand Up @@ -177,6 +177,7 @@ async def suggestion_down_vote(
await update_suggestion_message(suggestion=suggestion, bot=self.bot)

@components.button_listener()
@wrap_with_error_handler()
async def queue_approve(self, inter: disnake.MessageInteraction):
ih = await InteractionHandler.new_handler(inter)
qs = await QueuedSuggestion.from_message_id(
Expand All @@ -188,6 +189,7 @@ async def queue_approve(self, inter: disnake.MessageInteraction):
await ih.send(translation_key="PAGINATION_INNER_QUEUE_ACCEPTED")

@components.button_listener()
@wrap_with_error_handler()
async def queue_reject(self, inter: disnake.MessageInteraction):
ih = await InteractionHandler.new_handler(inter)
qs = await QueuedSuggestion.from_message_id(
Expand Down
1 change: 0 additions & 1 deletion suggestions/core/suggestion_notes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import disnake
import logoo
from disnake import Embed
from logoo import Logger

Expand Down
15 changes: 1 addition & 14 deletions suggestions/core/suggestions_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from suggestions.interaction_handler import InteractionHandler
from suggestions.objects import GuildConfig, UserConfig, QueuedSuggestion
from suggestions.qs_paginator import QueuedSuggestionsPaginator
from suggestions.utility import wrap_with_error_handler

if TYPE_CHECKING:
from alaric import Document
Expand All @@ -26,20 +27,6 @@
log = logging.getLogger(__name__)


def wrap_with_error_handler():
def decorator(func: Callable):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
await args[0].bot.on_slash_command_error(args[1].interaction, e)

return wrapper

return decorator


class SuggestionsQueue:
"""
Approach to suggestions queue.
Expand Down
1 change: 1 addition & 0 deletions suggestions/utility/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .error_wrapper import wrap_with_error_handler
23 changes: 23 additions & 0 deletions suggestions/utility/error_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import functools
from typing import Callable

from suggestions.interaction_handler import InteractionHandler


def wrap_with_error_handler():
def decorator(func: Callable):
@functools.wraps(func)
async def wrapper(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
inter = (
args[1].interaction
if isinstance(args[1], InteractionHandler)
else args[1]
)
await args[0].bot.on_slash_command_error(inter, e)

return wrapper

return decorator

0 comments on commit d281c5b

Please sign in to comment.