I have a few thousand lines of code that consists of several normal and async functions. I want to save all the errors I receive in a file without trying/excepting or logging the entire code. I got acquainted with this excellent function by searching, but the problem is that this function does not receive the errors of the async function, I don't know the reason, but I guess because the code does not stop because of receiving the error, this happens, or maybe the problem is from the functions themselves. is async.
my def get all errors:
def myexcepthook(e_type, e_value, e_tb, org_excepthook=sys.excepthook):
#open error file for append
with open('errors.txt', 'a') as error_file:
sys.stderr = error_file
sys.stderr.write(f'\n--------------- Exception --------------\n')
# get time
now = datetime.now()
# write error and time
sys.stderr.write(f'TIME: {now}\n\n')
org_excepthook(e_type, e_value, e_tb)
sys.excepthook = myexcepthook
my main code (Simplified because it is too long):
async def riseforgame(m: CallbackQuery, move=None):
if move:
await m.message.edit('you win!')
else:
return None
The error I receive and it is not written in the file:
Telegram says: [400 MESSAGE_NOT_MODIFIED] - The message was not modified because you tried to edit it using the same content (caused by "messages.EditMessage")
Traceback (most recent call last):
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\dispatcher.py", line 240, in handler_worker
await handler.callback(self.client, *args)
File "c:\Users\HaM\Desktop\New folder\DLG.py", line 1296, in callback
await riseforgame(m, num)
File "c:\Users\HaM\Desktop\New folder\DLG.py", line 1029, in riseforgame
awermsg = await m.message.edit('you win!', reply_markup=InlineKeyboardMarkup([
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\types\messages_and_media\message.py", line 2803, in edit_text
return await self._client.edit_message_text(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\methods\messages\edit_message_text.py", line 82, in edit_message_text
r = await self.invoke(
^^^^^^^^^^^^^^^^^^
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\methods\advanced\invoke.py", line 79, in invoke
r = await self.session.invoke(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\session\session.py", line 389, in invoke
return await self.send(query, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\session\session.py", line 357, in send
RPCError.raise_it(result, type(data))
File "C:\Users\HaM\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\pyrogram\errors\rpc_error.py", line 91, in raise_it
raise getattr(
pyrogram.errors.exceptions.bad_request_400.MessageNotModified: Telegram says: [400 MESSAGE_NOT_MODIFIED] - The message was not modified because you tried to edit it using the same content (caused by "messages.EditMessage")
Thank you for helping me