Skip to content

Commit

Permalink
Include full request on the cause of RPC errors
Browse files Browse the repository at this point in the history
Closes #3110, fixes #3109.
  • Loading branch information
Lonami committed Aug 29, 2021
1 parent 2cb6cd5 commit 8c56f95
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion telethon/errors/rpcbaseerrors.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from ..tl import functions

_NESTS_QUERY = (
functions.InvokeAfterMsgRequest,
functions.InvokeAfterMsgsRequest,
functions.InitConnectionRequest,
functions.InvokeWithLayerRequest,
functions.InvokeWithoutUpdatesRequest,
functions.InvokeWithMessagesRangeRequest,
functions.InvokeWithTakeoutRequest,
)

class RPCError(Exception):
"""Base class for all Remote Procedure Call errors."""
code = None
Expand All @@ -13,7 +25,15 @@ def __init__(self, request, message, code=None):

@staticmethod
def _fmt_request(request):
return ' (caused by {})'.format(request.__class__.__name__)
n = 0
reason = ''
while isinstance(request, _NESTS_QUERY):
n += 1
reason += request.__class__.__name__ + '('
request = request.query
reason += request.__class__.__name__ + ')' * n

return ' (caused by {})'.format(reason)

def __reduce__(self):
return type(self), (self.request, self.message, self.code)
Expand Down

0 comments on commit 8c56f95

Please sign in to comment.