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

@@ -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