@@ -59,17 +59,23 @@ async def on_command_error(self, ctx: Context, e: errors.CommandError) -> None:
5959 log .trace (f"Command { command } had its error already handled locally; ignoring." )
6060 return
6161
62+ debug_message = (
63+ f"Command { command } invoked by { ctx .message .author } with error "
64+ f"{ e .__class__ .__name__ } : { e } "
65+ )
66+
6267 if isinstance (e , errors .CommandNotFound ) and not getattr (ctx , "invoked_from_error_handler" , False ):
6368 if await self .try_silence (ctx ):
6469 return
65- # Try to look for a tag with the command's name
66- await self .try_get_tag (ctx )
67- return # Exit early to avoid logging.
70+ await self .try_get_tag (ctx ) # Try to look for a tag with the command's name
6871 elif isinstance (e , errors .UserInputError ):
72+ log .debug (debug_message )
6973 await self .handle_user_input_error (ctx , e )
7074 elif isinstance (e , errors .CheckFailure ):
75+ log .debug (debug_message )
7176 await self .handle_check_failure (ctx , e )
7277 elif isinstance (e , errors .CommandOnCooldown ):
78+ log .debug (debug_message )
7379 await ctx .send (e )
7480 elif isinstance (e , errors .CommandInvokeError ):
7581 if isinstance (e .original , ResponseCodeError ):
@@ -80,22 +86,16 @@ async def on_command_error(self, ctx: Context, e: errors.CommandError) -> None:
8086 await ctx .send (f"Cannot infract that user. { e .original .reason } " )
8187 else :
8288 await self .handle_unexpected_error (ctx , e .original )
83- return # Exit early to avoid logging.
8489 elif isinstance (e , errors .ConversionError ):
8590 if isinstance (e .original , ResponseCodeError ):
8691 await self .handle_api_error (ctx , e .original )
8792 else :
8893 await self .handle_unexpected_error (ctx , e .original )
89- return # Exit early to avoid logging.
90- elif not isinstance (e , errors .DisabledCommand ):
94+ elif isinstance (e , errors .DisabledCommand ):
95+ log .debug (debug_message )
96+ else :
9197 # MaxConcurrencyReached, ExtensionError
9298 await self .handle_unexpected_error (ctx , e )
93- return # Exit early to avoid logging.
94-
95- log .debug (
96- f"Command { command } invoked by { ctx .message .author } with error "
97- f"{ e .__class__ .__name__ } : { e } "
98- )
9999
100100 @staticmethod
101101 def get_help_command (ctx : Context ) -> t .Coroutine :
@@ -188,9 +188,6 @@ async def try_get_tag(self, ctx: Context) -> None:
188188 if not any (role .id in MODERATION_ROLES for role in ctx .author .roles ):
189189 await self .send_command_suggestion (ctx , ctx .invoked_with )
190190
191- # Return to not raise the exception
192- return
193-
194191 async def send_command_suggestion (self , ctx : Context , command_name : str ) -> None :
195192 """Sends user similar commands if any can be found."""
196193 # No similar tag found, or tag on cooldown -
@@ -235,38 +232,32 @@ async def handle_user_input_error(self, ctx: Context, e: errors.UserInputError)
235232 """
236233 if isinstance (e , errors .MissingRequiredArgument ):
237234 embed = self ._get_error_embed ("Missing required argument" , e .param .name )
238- await ctx .send (embed = embed )
239- await self .get_help_command (ctx )
240235 self .bot .stats .incr ("errors.missing_required_argument" )
241236 elif isinstance (e , errors .TooManyArguments ):
242237 embed = self ._get_error_embed ("Too many arguments" , str (e ))
243- await ctx .send (embed = embed )
244- await self .get_help_command (ctx )
245238 self .bot .stats .incr ("errors.too_many_arguments" )
246239 elif isinstance (e , errors .BadArgument ):
247240 embed = self ._get_error_embed ("Bad argument" , str (e ))
248- await ctx .send (embed = embed )
249- await self .get_help_command (ctx )
250241 self .bot .stats .incr ("errors.bad_argument" )
251242 elif isinstance (e , errors .BadUnionArgument ):
252243 embed = self ._get_error_embed ("Bad argument" , f"{ e } \n { e .errors [- 1 ]} " )
253- await ctx .send (embed = embed )
254- await self .get_help_command (ctx )
255244 self .bot .stats .incr ("errors.bad_union_argument" )
256245 elif isinstance (e , errors .ArgumentParsingError ):
257246 embed = self ._get_error_embed ("Argument parsing error" , str (e ))
258247 await ctx .send (embed = embed )
259248 self .get_help_command (ctx ).close ()
260249 self .bot .stats .incr ("errors.argument_parsing_error" )
250+ return
261251 else :
262252 embed = self ._get_error_embed (
263253 "Input error" ,
264254 "Something about your input seems off. Check the arguments and try again."
265255 )
266- await ctx .send (embed = embed )
267- await self .get_help_command (ctx )
268256 self .bot .stats .incr ("errors.other_user_input_error" )
269257
258+ await ctx .send (embed = embed )
259+ await self .get_help_command (ctx )
260+
270261 @staticmethod
271262 async def handle_check_failure (ctx : Context , e : errors .CheckFailure ) -> None :
272263 """
@@ -299,21 +290,21 @@ async def handle_check_failure(ctx: Context, e: errors.CheckFailure) -> None:
299290 async def handle_api_error (ctx : Context , e : ResponseCodeError ) -> None :
300291 """Send an error message in `ctx` for ResponseCodeError and log it."""
301292 if e .status == 404 :
302- await ctx .send ("There does not seem to be anything matching your query." )
303293 log .debug (f"API responded with 404 for command { ctx .command } " )
294+ await ctx .send ("There does not seem to be anything matching your query." )
304295 ctx .bot .stats .incr ("errors.api_error_404" )
305296 elif e .status == 400 :
306297 content = await e .response .json ()
307298 log .debug (f"API responded with 400 for command { ctx .command } : %r." , content )
308299 await ctx .send ("According to the API, your request is malformed." )
309300 ctx .bot .stats .incr ("errors.api_error_400" )
310301 elif 500 <= e .status < 600 :
311- await ctx .send ("Sorry, there seems to be an internal issue with the API." )
312302 log .warning (f"API responded with { e .status } for command { ctx .command } " )
303+ await ctx .send ("Sorry, there seems to be an internal issue with the API." )
313304 ctx .bot .stats .incr ("errors.api_internal_server_error" )
314305 else :
315- await ctx .send (f"Got an unexpected status code from the API (`{ e .status } `)." )
316306 log .warning (f"Unexpected API response for command { ctx .command } : { e .status } " )
307+ await ctx .send (f"Got an unexpected status code from the API (`{ e .status } `)." )
317308 ctx .bot .stats .incr (f"errors.api_error_{ e .status } " )
318309
319310 @staticmethod
0 commit comments