Move error capture names to errors.csv

This commit is contained in:
Lonami Exo 2018-12-03 11:08:20 +01:00
parent 4d8f078ad9
commit 01848de7e2
3 changed files with 14 additions and 34 deletions

View File

@ -18,7 +18,7 @@ BOT_CHANNELS_NA,400,Bots can't edit admin privileges
BOT_GROUPS_BLOCKED,400,This bot can't be added to groups
BOT_INLINE_DISABLED,400,This bot can't be used in inline mode
BOT_INVALID,400,This is not a valid bot
BOT_METHOD_INVALID,,The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot
BOT_METHOD_INVALID,400,The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot
BOT_MISSING,400,This method can only be run by a bot
BUTTON_DATA_INVALID,400,The provided button data is invalid
BUTTON_TYPE_INVALID,400,The type of one of the buttons you provided is invalid
@ -76,17 +76,17 @@ EXTERNAL_URL_INVALID,400,External URL invalid
FIELD_NAME_EMPTY,,The field with the name FIELD_NAME is missing
FIELD_NAME_INVALID,,The field with the name FIELD_NAME is invalid
FILE_ID_INVALID,400,The provided file id is invalid
FILE_MIGRATE_X,303,The file to be accessed is currently stored in DC {}
FILE_MIGRATE_X,303,The file to be accessed is currently stored in DC {new_dc}
FILE_PARTS_INVALID,400,The number of file parts is invalid
FILE_PART_0_MISSING,,File part 0 missing
FILE_PART_EMPTY,400,The provided file part is empty
FILE_PART_INVALID,400,The file part number is invalid
FILE_PART_LENGTH_INVALID,400,The length of a file part is invalid
FILE_PART_SIZE_INVALID,400,The provided file part size is invalid
FILE_PART_X_MISSING,,Part {} of the file is missing from storage
FILE_PART_X_MISSING,400,Part {which} of the file is missing from storage
FIRSTNAME_INVALID,400,The first name is invalid
FLOOD_TEST_PHONE_WAIT_X,420,A wait of {} seconds is required in the test servers
FLOOD_WAIT_X,420,A wait of {} seconds is required
FLOOD_TEST_PHONE_WAIT_X,420,A wait of {seconds} seconds is required in the test servers
FLOOD_WAIT_X,420,A wait of {seconds} seconds is required
GIF_ID_INVALID,400,The provided GIF ID is invalid
GROUPED_MEDIA_INVALID,400,Invalid grouped media
HASH_INVALID,400,The provided hash is invalid
@ -100,16 +100,8 @@ INPUT_LAYER_INVALID,400,The provided layer is invalid
INPUT_METHOD_INVALID,,The invoked method does not exist anymore or has never existed
INPUT_REQUEST_TOO_LONG,400,The input request was too long. This may be a bug in the library as it can occur when serializing more bytes than it should (like appending the vector constructor code at the end of a message)
INPUT_USER_DEACTIVATED,400,The specified user was deleted
INTERDC_1_CALL_ERROR,,An error occurred while communicating with DC 1
INTERDC_1_CALL_RICH_ERROR,,A rich error occurred while communicating with DC 1
INTERDC_2_CALL_ERROR,,An error occurred while communicating with DC 2
INTERDC_2_CALL_RICH_ERROR,,A rich error occurred while communicating with DC 2
INTERDC_3_CALL_ERROR,,An error occurred while communicating with DC 3
INTERDC_3_CALL_RICH_ERROR,,A rich error occurred while communicating with DC 3
INTERDC_4_CALL_ERROR,,An error occurred while communicating with DC 4
INTERDC_4_CALL_RICH_ERROR,,A rich error occurred while communicating with DC 4
INTERDC_5_CALL_ERROR,,An error occurred while communicating with DC 5
INTERDC_5_CALL_RICH_ERROR,,A rich error occurred while communicating with DC 5
INTERDC_X_CALL_ERROR,,An error occurred while communicating with DC {dc}
INTERDC_X_CALL_RICH_ERROR,,A rich error occurred while communicating with DC {dc}
INVITE_HASH_EMPTY,400,The invite hash is empty
INVITE_HASH_EXPIRED,400,The chat the user tried to join has expired and is not valid anymore
INVITE_HASH_INVALID,400,The invite hash is invalid
@ -137,7 +129,7 @@ MESSAGE_TOO_LONG,400,Message was too long. Current maximum length is 4096 UTF-8
MSG_WAIT_FAILED,400,A waiting call returned an error
NEED_CHAT_INVALID,500,The provided chat is invalid
NEED_MEMBER_INVALID,500,The provided member is invalid
NETWORK_MIGRATE_X,303,The source IP address is associated with DC {}
NETWORK_MIGRATE_X,303,The source IP address is associated with DC {new_dc}
NEW_SALT_INVALID,400,The new salt is invalid
NEW_SETTINGS_INVALID,400,The new settings are invalid
OFFSET_INVALID,400,"The given offset was invalid, it must be divisible by 1KB. See https://core.telegram.org/api/files#downloading-files"
@ -159,7 +151,7 @@ PHONE_CODE_EMPTY,400,The phone code is missing
PHONE_CODE_EXPIRED,400,The confirmation code has expired
PHONE_CODE_HASH_EMPTY,,The phone code hash is missing
PHONE_CODE_INVALID,400,The phone code entered was invalid
PHONE_MIGRATE_X,303,The phone number a user is trying to use for authorization is associated with DC {}
PHONE_MIGRATE_X,303,The phone number a user is trying to use for authorization is associated with DC {new_dc}
PHONE_NUMBER_APP_SIGNUP_FORBIDDEN,400,
PHONE_NUMBER_BANNED,400,The used phone number has been banned from Telegram and cannot be used anymore. Maybe check https://www.telegram.org/faq_spam
PHONE_NUMBER_FLOOD,400,You asked for the code too many times.
@ -208,7 +200,7 @@ STICKER_INVALID,400,The provided sticker is invalid
STICKER_PNG_DIMENSIONS,400,Sticker png dimensions invalid
STORAGE_CHECK_FAILED,500,Server storage check failed
STORE_INVALID_SCALAR_TYPE,500,
TAKEOUT_INIT_DELAY_X,420,A wait of {} seconds is required before being able to initiate the takeout
TAKEOUT_INIT_DELAY_X,420,A wait of {seconds} seconds is required before being able to initiate the takeout
TAKEOUT_REQUIRED,400,You must initialize a takeout request first
TEMP_AUTH_KEY_EMPTY,400,No temporary auth key provided
Timeout,-503,A timeout occurred while fetching data from the bot
@ -239,7 +231,7 @@ USER_ID_INVALID,400,"Invalid object ID for a user. Make sure to pass the right t
USER_IS_BLOCKED,400 403,User is blocked
USER_IS_BOT,400,Bots can't send messages to other bots
USER_KICKED,400,This user was kicked from this supergroup/channel
USER_MIGRATE_X,303,The user whose identity is being used to execute queries is associated with DC {}
USER_MIGRATE_X,303,The user whose identity is being used to execute queries is associated with DC {new_dc}
USER_NOT_MUTUAL_CONTACT,400 403,The provided user is not a mutual contact
USER_NOT_PARTICIPANT,400,The target user is not a member of the specified megagroup or channel
USER_PRIVACY_RESTRICTED,403,The user's privacy settings do not allow you to do this

1 name codes description
18 BOT_GROUPS_BLOCKED 400 This bot can't be added to groups
19 BOT_INLINE_DISABLED 400 This bot can't be used in inline mode
20 BOT_INVALID 400 This is not a valid bot
21 BOT_METHOD_INVALID 400 The API access for bot users is restricted. The method you tried to invoke cannot be executed as a bot
22 BOT_MISSING 400 This method can only be run by a bot
23 BUTTON_DATA_INVALID 400 The provided button data is invalid
24 BUTTON_TYPE_INVALID 400 The type of one of the buttons you provided is invalid
76 FIELD_NAME_EMPTY The field with the name FIELD_NAME is missing
77 FIELD_NAME_INVALID The field with the name FIELD_NAME is invalid
78 FILE_ID_INVALID 400 The provided file id is invalid
79 FILE_MIGRATE_X 303 The file to be accessed is currently stored in DC {} The file to be accessed is currently stored in DC {new_dc}
80 FILE_PARTS_INVALID 400 The number of file parts is invalid
81 FILE_PART_0_MISSING File part 0 missing
82 FILE_PART_EMPTY 400 The provided file part is empty
83 FILE_PART_INVALID 400 The file part number is invalid
84 FILE_PART_LENGTH_INVALID 400 The length of a file part is invalid
85 FILE_PART_SIZE_INVALID 400 The provided file part size is invalid
86 FILE_PART_X_MISSING 400 Part {} of the file is missing from storage Part {which} of the file is missing from storage
87 FIRSTNAME_INVALID 400 The first name is invalid
88 FLOOD_TEST_PHONE_WAIT_X 420 A wait of {} seconds is required in the test servers A wait of {seconds} seconds is required in the test servers
89 FLOOD_WAIT_X 420 A wait of {} seconds is required A wait of {seconds} seconds is required
90 GIF_ID_INVALID 400 The provided GIF ID is invalid
91 GROUPED_MEDIA_INVALID 400 Invalid grouped media
92 HASH_INVALID 400 The provided hash is invalid
100 INPUT_METHOD_INVALID The invoked method does not exist anymore or has never existed
101 INPUT_REQUEST_TOO_LONG 400 The input request was too long. This may be a bug in the library as it can occur when serializing more bytes than it should (like appending the vector constructor code at the end of a message)
102 INPUT_USER_DEACTIVATED 400 The specified user was deleted
103 INTERDC_1_CALL_ERROR INTERDC_X_CALL_ERROR An error occurred while communicating with DC 1 An error occurred while communicating with DC {dc}
104 INTERDC_1_CALL_RICH_ERROR INTERDC_X_CALL_RICH_ERROR A rich error occurred while communicating with DC 1 A rich error occurred while communicating with DC {dc}
INTERDC_2_CALL_ERROR An error occurred while communicating with DC 2
INTERDC_2_CALL_RICH_ERROR A rich error occurred while communicating with DC 2
INTERDC_3_CALL_ERROR An error occurred while communicating with DC 3
INTERDC_3_CALL_RICH_ERROR A rich error occurred while communicating with DC 3
INTERDC_4_CALL_ERROR An error occurred while communicating with DC 4
INTERDC_4_CALL_RICH_ERROR A rich error occurred while communicating with DC 4
INTERDC_5_CALL_ERROR An error occurred while communicating with DC 5
INTERDC_5_CALL_RICH_ERROR A rich error occurred while communicating with DC 5
105 INVITE_HASH_EMPTY 400 The invite hash is empty
106 INVITE_HASH_EXPIRED 400 The chat the user tried to join has expired and is not valid anymore
107 INVITE_HASH_INVALID 400 The invite hash is invalid
129 MSG_WAIT_FAILED 400 A waiting call returned an error
130 NEED_CHAT_INVALID 500 The provided chat is invalid
131 NEED_MEMBER_INVALID 500 The provided member is invalid
132 NETWORK_MIGRATE_X 303 The source IP address is associated with DC {} The source IP address is associated with DC {new_dc}
133 NEW_SALT_INVALID 400 The new salt is invalid
134 NEW_SETTINGS_INVALID 400 The new settings are invalid
135 OFFSET_INVALID 400 The given offset was invalid, it must be divisible by 1KB. See https://core.telegram.org/api/files#downloading-files
151 PHONE_CODE_EXPIRED 400 The confirmation code has expired
152 PHONE_CODE_HASH_EMPTY The phone code hash is missing
153 PHONE_CODE_INVALID 400 The phone code entered was invalid
154 PHONE_MIGRATE_X 303 The phone number a user is trying to use for authorization is associated with DC {} The phone number a user is trying to use for authorization is associated with DC {new_dc}
155 PHONE_NUMBER_APP_SIGNUP_FORBIDDEN 400
156 PHONE_NUMBER_BANNED 400 The used phone number has been banned from Telegram and cannot be used anymore. Maybe check https://www.telegram.org/faq_spam
157 PHONE_NUMBER_FLOOD 400 You asked for the code too many times.
200 STICKER_PNG_DIMENSIONS 400 Sticker png dimensions invalid
201 STORAGE_CHECK_FAILED 500 Server storage check failed
202 STORE_INVALID_SCALAR_TYPE 500
203 TAKEOUT_INIT_DELAY_X 420 A wait of {} seconds is required before being able to initiate the takeout A wait of {seconds} seconds is required before being able to initiate the takeout
204 TAKEOUT_REQUIRED 400 You must initialize a takeout request first
205 TEMP_AUTH_KEY_EMPTY 400 No temporary auth key provided
206 Timeout -503 A timeout occurred while fetching data from the bot
231 USER_IS_BLOCKED 400 403 User is blocked
232 USER_IS_BOT 400 Bots can't send messages to other bots
233 USER_KICKED 400 This user was kicked from this supergroup/channel
234 USER_MIGRATE_X 303 The user whose identity is being used to execute queries is associated with DC {} The user whose identity is being used to execute queries is associated with DC {new_dc}
235 USER_NOT_MUTUAL_CONTACT 400 403 The provided user is not a mutual contact
236 USER_NOT_PARTICIPANT 400 The target user is not a member of the specified megagroup or channel
237 USER_PRIVACY_RESTRICTED 403 The user's privacy settings do not allow you to do this

View File

@ -38,7 +38,7 @@ def generate_errors(errors, f):
'{}'.format(repr(error.description)))
if error.has_captures:
f.write('.format(self.{})'.format(error.capture_name))
f.write('.format({0}=self.{0})'.format(error.capture_name))
f.write(' + self._fmt_request(request))\n')

View File

@ -1,4 +1,5 @@
import csv
import re
from ..utils import snake_to_camel_case
@ -14,19 +15,6 @@ KNOWN_BASE_CLASSES = {
500: 'ServerError',
}
# Give better semantic names to some captures
# TODO Move this to the CSV?
CAPTURE_NAMES = {
'FloodWaitError': 'seconds',
'FloodTestPhoneWaitError': 'seconds',
'TakeoutInitDelayError': 'seconds',
'FileMigrateError': 'new_dc',
'NetworkMigrateError': 'new_dc',
'PhoneMigrateError': 'new_dc',
'UserMigrateError': 'new_dc',
'FilePartMissingError': 'which'
}
def _get_class_name(error_code):
"""
@ -57,7 +45,7 @@ class Error:
if self.has_captures:
self.name = _get_class_name(name.replace('_X', ''))
self.pattern = name.replace('_X', r'_(\d+)')
self.capture_name = CAPTURE_NAMES.get(self.name, 'x')
self.capture_name = re.search(r'{(\w+)}', description).group(1)
else:
self.name = _get_class_name(name)
self.pattern = name