From e6981e767649226474378275ff2bd05825aa313a Mon Sep 17 00:00:00 2001 From: josephbiko Date: Mon, 9 Jul 2018 20:54:43 +0200 Subject: [PATCH] Remove empty except (#887) --- readthedocs/extra/developing/test-servers.rst | 4 ++-- telethon/client/updates.py | 7 +++++-- telethon/errors/__init__.py | 2 +- telethon/network/mtprotosender.py | 12 +++++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/readthedocs/extra/developing/test-servers.rst b/readthedocs/extra/developing/test-servers.rst index bf8fd97e..98f93755 100644 --- a/readthedocs/extra/developing/test-servers.rst +++ b/readthedocs/extra/developing/test-servers.rst @@ -32,6 +32,6 @@ times, in this case, ``22222`` so we can hardcode that: client = TelegramClient(None, api_id, api_hash) client.session.set_dc(2, '149.154.167.40', 80) - loop.run_until_complete(client.start( + client.start( phone='9996621234', code_callback=lambda: '22222' - )) + ) diff --git a/telethon/client/updates.py b/telethon/client/updates.py index 220a08ae..2b6f6a4e 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -210,7 +210,10 @@ class UpdateMethods(UserMethods): continue # We actually just want to act upon timeout except asyncio.TimeoutError: pass - except: + except asyncio.CancelledError: + await self.disconnect() + return + except Exception as e: continue # Any disconnected exception should be ignored # We also don't really care about their result. @@ -273,7 +276,7 @@ class UpdateMethods(UserMethods): type(event).__name__) ) break - except: + except Exception: __log__.exception('Unhandled exception on {}' .format(callback.__name__)) diff --git a/telethon/errors/__init__.py b/telethon/errors/__init__.py index c1c7a6b3..a88459eb 100644 --- a/telethon/errors/__init__.py +++ b/telethon/errors/__init__.py @@ -36,7 +36,7 @@ def report_error(code, message, report_method): ) url.read() url.close() - except: + except Exception as e: "We really don't want to crash when just reporting an error" diff --git a/telethon/network/mtprotosender.py b/telethon/network/mtprotosender.py index 81deae64..481dd974 100644 --- a/telethon/network/mtprotosender.py +++ b/telethon/network/mtprotosender.py @@ -386,6 +386,7 @@ class MTProtoSender: except asyncio.TimeoutError: continue except asyncio.CancelledError: + await self.disconnect() return except Exception as e: if isinstance(e, ConnectionError): @@ -425,6 +426,7 @@ class MTProtoSender: except asyncio.TimeoutError: continue except asyncio.CancelledError: + await self.disconnect() return except Exception as e: if isinstance(e, ConnectionError): @@ -467,15 +469,19 @@ class MTProtoSender: __log__.info('Server replied with an unknown type {:08x}: {!r}' .format(e.invalid_constructor_id, e.remaining)) continue - except: - __log__.exception('Unhandled exception while unpacking') + except asyncio.CancelledError: + await self.disconnect() + return + except Exception as e: + __log__.exception('Unhandled exception while unpacking %s',e) await asyncio.sleep(1) else: try: await self._process_message(message) except asyncio.CancelledError: + await self.disconnect() return - except: + except Exception as e: __log__.exception('Unhandled exception while ' 'processing %s', message) await asyncio.sleep(1)