From 6da8d1a0ec7b5fd5d5bc17a97ee9e8216ece315c Mon Sep 17 00:00:00 2001 From: Lonami Date: Tue, 24 Sep 2019 19:01:46 +0200 Subject: [PATCH] Less confusing error for getting marked ID of PeerChannel(0) Fixes #1282. --- telethon/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/telethon/utils.py b/telethon/utils.py index 5fcb4d42..9f18da29 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -903,8 +903,12 @@ def get_peer_id(peer, add_mark=True): # Concat -100 through math tricks, .to_supergroup() on # Madeline IDs will be strictly positive -> log works. - return -(peer.channel_id + pow( - 10, math.floor(math.log10(peer.channel_id) + 3))) + try: + return -(peer.channel_id + pow( + 10, math.floor(math.log10(peer.channel_id) + 3))) + except ValueError: + raise TypeError('Cannot get marked ID of a channel ' + 'unless its ID is strictly positive') from None def resolve_id(marked_id):