Separate errors needing regex from those which don't

This commit is contained in:
Lonami Exo 2018-06-18 19:09:45 +02:00
parent 463847ad50
commit fbf3bf119c
2 changed files with 8 additions and 7 deletions

View File

@ -55,12 +55,11 @@ def rpc_message_to_error(rpc_error, report_method=None):
).start() ).start()
# Try to get the error by direct look-up, otherwise regex # Try to get the error by direct look-up, otherwise regex
# TODO Maybe regexes could live in a separate dictionary? cls = rpc_errors_dict.get(rpc_error.error_message, None)
cls = rpc_errors_all.get(rpc_error.error_message, None)
if cls: if cls:
return cls() return cls()
for msg_regex, cls in rpc_errors_all.items(): for msg_regex, cls in rpc_errors_re:
m = re.match(msg_regex, rpc_error.error_message) m = re.match(msg_regex, rpc_error.error_message)
if m: if m:
capture = int(m.group(1)) if m.groups() else None capture = int(m.group(1)) if m.groups() else None

View File

@ -45,8 +45,10 @@ def generate_errors(errors, f):
f.write(')\n') f.write(')\n')
# Create the actual {CODE: ErrorClassName} dict once classes are defined # Create the actual {CODE: ErrorClassName} dict once classes are defined
# TODO Actually make a difference between regex/exact f.write('\n\nrpc_errors_dict = {\n')
f.write('\n\nrpc_errors_all = {\n') for error in exact_match:
for error in itertools.chain(regex_match, exact_match):
f.write(' {}: {},\n'.format(repr(error.pattern), error.name)) f.write(' {}: {},\n'.format(repr(error.pattern), error.name))
f.write('}\n') f.write('}\n\nrpc_errors_re = (\n')
for error in regex_match:
f.write(' ({}, {}),\n'.format(repr(error.pattern), error.name))
f.write(')\n')