def _handle_exception(self, sender, exception=None): """ Actual code handling the exception and sending it to honeybadger if it's enabled. :param T sender: the object sending the exception event. :param Exception exception: the exception to handle. """ honeybadger.notify(exception) if self.reset_context_after_request: self._reset_context()
async def on_command_error(self, ctx, err): if hasattr(ctx.command, "on_error"): return # Don't interfere with custom error handlers gstate = state_instance.get_state(ctx.guild.id) if isinstance(err, errors.MissingRequiredArgument) or isinstance( err, errors.BadArgument): helper = str( ctx.invoked_subcommand) if ctx.invoked_subcommand else str( ctx.command) await ctx.send( "Bruh, take a look at the syntax of this command (ˉ﹃ˉ)") await ctx.send_help(helper) elif isinstance(err, errors.CommandInvokeError): error = f"Command invoke error:\n{default.traceback_maker(err.original)}" if "2000 or fewer" in str(err) or len( ctx.message.clean_content) > 1900: return await ctx.send( "You attempted to make the command display more than 2,000 characters...\n" f"Both error and command will be ignored. Baka.") await ctx.send("There was an error processing the command ಥ_ಥ") honeybadger.notify(err, context={ 'Command': ctx.message.clean_content, 'Traceback': default.traceback_maker(err.original, only_traceback=True) }) logging.error("Ignoring exception in command {}:".format( ctx.command)) logging.error("\n" + "".join( traceback.format_exception(type(error), err, err.__traceback__))) elif isinstance(err, errors.CheckFailure): pass elif isinstance(err, errors.CommandOnCooldown): embed = discord.Embed( title="Cooldown", color=discord.Colour.from_rgb(0, 250, 141), description="**This command is on cooldown... try again in {}**" .format(default.format_seconds(err.retry_after)), timestamp=ctx.message.created_at) await ctx.send(embed=embed) if isinstance(err, commands.CommandNotFound): if not gstate.debugmode: return await ctx.send(f'>>> No command "{ctx.invoked_with}" found.', delete_after=5)
async def _run_app(self, scope, callback): # TODO: Should we check recursive middleware stacks? # See: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/asgi.py#L112 try: return await callback() except Exception as exc: honeybadger.notify(exception=exc, context=_as_context(scope)) raise exc from None finally: honeybadger.reset_context()
async def custom_route_handler(request: Request): try: return await original_route_handler(request) except exceptions.HTTPException as exc: raise exc from None except Exception as exc: body = await request.body() scope = dict(request) scope["body"] = body honeybadger.notify(exception=exc, context=asgi._as_context(scope)) raise exc from None finally: honeybadger.reset_context()
def wrapped_handler(aws_event, aws_context, *args, **kwargs): set_event(aws_event) honeybadger.begin_request(aws_event) try: return handler(aws_event, aws_context, *args, **kwargs) except Exception as e: honeybadger.notify(e) exc_info = sys.exc_info() clear_event() honeybadger.reset_context() #Rerase exception to proceed with normal aws error handling reraise(*exc_info)
def get_base_logic(self): honeybadger.notify(error_class='Exception', error_message='Test Message') return { "hello": "world", "count": len(User.all()) }
def process_exception(self, request, exception): honeybadger.notify(exception) return None
def method_two(): mydict = dict(a=1) try: print(mydict['b']) except KeyError as exc: honeybadger.notify(exc, context={'foo': 'bar'})
def handle_exception(self, exception=None): """ Actual code handling the exception and sending it to honeybadger if it's enabled. :param Exception exception: the exception to handle. """ honeybadger.notify(exception)
def dummy_task(x, y=1): try: return x / y except ZeroDivisionError as e: honeybadger.notify(e, context={'q': 3})