2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-23 02:17:21 +00:00

Rename RPCError.x to RPCError.value

This commit is contained in:
Dan 2022-04-24 11:56:07 +02:00
parent 68f151bad5
commit 0e3c2e4412
13 changed files with 23 additions and 23 deletions

View File

@ -30,11 +30,11 @@ class RPCError(Exception):
ID = None
CODE = None
NAME = None
MESSAGE = "{x}"
MESSAGE = "{value}"
def __init__(
self,
x: Union[int, str, raw.types.RpcError] = None,
value: Union[int, str, raw.types.RpcError] = None,
rpc_name: str = None,
is_unknown: bool = False,
is_signed: bool = False
@ -43,18 +43,18 @@ class RPCError(Exception):
"-" if is_signed else "",
self.CODE,
self.ID or self.NAME,
self.MESSAGE.format(x=x),
self.MESSAGE.format(value=value),
f'(caused by "{rpc_name}")' if rpc_name else ""
))
try:
self.x = int(x)
self.value = int(value)
except (ValueError, TypeError):
self.x = x
self.value = value
if is_unknown:
with open("unknown_errors.txt", "a", encoding="utf-8") as f:
f.write(f"{datetime.now()}\t{x}\t{rpc_name}\n")
f.write(f"{datetime.now()}\t{value}\t{rpc_name}\n")
@staticmethod
def raise_it(rpc_error: "raw.types.RpcError", rpc_type: Type[TLObject]):
@ -68,7 +68,7 @@ class RPCError(Exception):
if error_code not in exceptions:
raise UnknownError(
x=f"[{error_code} {error_message}]",
value=f"[{error_code} {error_message}]",
rpc_name=rpc_name,
is_unknown=True,
is_signed=is_signed
@ -80,18 +80,18 @@ class RPCError(Exception):
raise getattr(
import_module("pyrogram.errors"),
exceptions[error_code]["_"]
)(x=f"[{error_code} {error_message}]",
)(value=f"[{error_code} {error_message}]",
rpc_name=rpc_name,
is_unknown=True,
is_signed=is_signed)
x = re.search(r"_(\d+)", error_message)
x = x.group(1) if x is not None else x
value = re.search(r"_(\d+)", error_message)
value = value.group(1) if value is not None else value
raise getattr(
import_module("pyrogram.errors"),
exceptions[error_code][error_id]
)(x=x,
)(value=value,
rpc_name=rpc_name,
is_unknown=False,
is_signed=is_signed)

View File

@ -60,7 +60,7 @@ class SendCode:
except (PhoneMigrate, NetworkMigrate) as e:
await self.session.stop()
await self.storage.dc_id(e.x)
await self.storage.dc_id(e.value)
await self.storage.auth_key(
await Auth(
self, await self.storage.dc_id(),

View File

@ -57,7 +57,7 @@ class SignInBot:
except UserMigrate as e:
await self.session.stop()
await self.storage.dc_id(e.x)
await self.storage.dc_id(e.value)
await self.storage.auth_key(
await Auth(
self, await self.storage.dc_id(),

View File

@ -84,7 +84,7 @@ class GetInlineBotResults:
)
except UnknownError as e:
# TODO: Add this -503 Timeout error into the Error DB
if e.x.error_code == -503 and e.x.error_message == "Timeout":
if e.value.error_code == -503 and e.value.error_message == "Timeout":
raise TimeoutError("The inline bot didn't answer in time") from None
else:
raise e

View File

@ -230,7 +230,7 @@ class SendAnimation:
)
)
except FilePartMissing as e:
await self.save_file(animation, file_id=file.id, file_part=e.x)
await self.save_file(animation, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -224,7 +224,7 @@ class SendAudio:
)
)
except FilePartMissing as e:
await self.save_file(audio, file_id=file.id, file_part=e.x)
await self.save_file(audio, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -202,7 +202,7 @@ class SendDocument:
)
)
except FilePartMissing as e:
await self.save_file(document, file_id=file.id, file_part=e.x)
await self.save_file(document, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -179,7 +179,7 @@ class SendPhoto:
)
)
except FilePartMissing as e:
await self.save_file(photo, file_id=file.id, file_part=e.x)
await self.save_file(photo, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -161,7 +161,7 @@ class SendSticker:
)
)
except FilePartMissing as e:
await self.save_file(sticker, file_id=file.id, file_part=e.x)
await self.save_file(sticker, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -236,7 +236,7 @@ class SendVideo:
)
)
except FilePartMissing as e:
await self.save_file(video, file_id=file.id, file_part=e.x)
await self.save_file(video, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -185,7 +185,7 @@ class SendVideoNote:
)
)
except FilePartMissing as e:
await self.save_file(video_note, file_id=file.id, file_part=e.x)
await self.save_file(video_note, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -186,7 +186,7 @@ class SendVoice:
)
)
except FilePartMissing as e:
await self.save_file(voice, file_id=file.id, file_part=e.x)
await self.save_file(voice, file_id=file.id, file_part=e.value)
else:
for i in r.updates:
if isinstance(i, (raw.types.UpdateNewMessage,

View File

@ -359,7 +359,7 @@ class Session:
try:
return await self.send(query, timeout=timeout)
except FloodWait as e:
amount = e.x
amount = e.value
if amount > sleep_threshold >= 0:
raise