pipermerriam / ethereum-function-signature-registry

Registry of 4byte function signatures and their human readable counterparts.
210 stars 46 forks source link

list index out of range during import / ParseError #90

Open pipermerriam opened 3 years ago

pipermerriam commented 3 years ago

What is wrong?

This error was reported in production:

Traceback (most recent call last):
  File "/home/web/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3.7/contextlib.py", line 74, in inner
    return func(*args, **kwds)
  File "/home/web/venv/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/web/venv/lib/python3.7/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/web/venv/lib/python3.7/site-packages/rest_framework/views.py", line 466, in dispatch
    response = self.handle_exception(exc)
  File "/home/web/venv/lib/python3.7/site-packages/rest_framework/views.py", line 463, in dispatch
    response = handler(request, *args, **kwargs)
  File "./func_sig_registry/registry/views.py", line 216, in post
    import_function_results.extend(Signature.import_from_solidity_file(file_obj))
  File "./func_sig_registry/registry/models.py", line 109, in import_from_solidity_file
    return cls.import_from_solidity_code(code)
  File "./func_sig_registry/registry/models.py", line 102, in import_from_solidity_code
    for raw_signature in function_signatures
  File "./func_sig_registry/registry/models.py", line 102, in <listcomp>
    for raw_signature in function_signatures
  File "./func_sig_registry/registry/models.py", line 87, in import_from_raw_text_signature
    text_signature = normalize_function_signature(raw_function_signature)
  File "./func_sig_registry/utils/solidity.py", line 189, in normalize_function_signature
    arg_types = ','.join(get_arg_types(args))
  File "./func_sig_registry/utils/solidity.py", line 169, in get_arg_types
    types = [p.strip().split(maxsplit=1)[0] for p in parts]
  File "./func_sig_registry/utils/solidity.py", line 169, in <listcomp>
    types = [p.strip().split(maxsplit=1)[0] for p in parts]
IndexError: list index out of rangeTraceback (most recent call last):
  File "./func_sig_registry/utils/solidity.py", line 185, in normalize_function_signature
    args_tuple_type = parse_type(normalize_type(f'({args})'))
  File "/home/web/venv/lib/python3.7/site-packages/eth_abi/grammar.py", line 125, in parse
    raise ParseError(e.text, e.pos, e.expr)
ParseError: Parse error at '  )' (column 2) in type string '(  )'Traceback (most recent call last):
  File "/home/web/venv/lib/python3.7/site-packages/eth_abi/grammar.py", line 123, in parse
    return super().parse(type_str)
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/nodes.py", line 254, in parse
    return self._parse_or_match(text, pos, 'parse')
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/nodes.py", line 289, in _parse_or_match
    return self.visit(getattr(self.grammar, method_name)(text, pos=pos))
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/grammar.py", line 115, in parse
    return self.default_rule.parse(text, pos=pos)
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/expressions.py", line 120, in parse
    node = self.match(text, pos=pos)
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/expressions.py", line 137, in match
    raise error
ParseError: Rule 'type' didn't match at '  )' (line 1, column 2).

How can it be fixed

Looks like just exception handling that needs to be put in place

pipermerriam commented 3 years ago

I think this is the same bug.

    return self.visit(getattr(self.grammar, method_name)(text, pos=pos))
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/grammar.py", line 115, in parse
    return self.default_rule.parse(text, pos=pos)
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/expressions.py", line 120, in parse
    node = self.match(text, pos=pos)
  File "/home/web/venv/lib/python3.7/site-packages/parsimonious/expressions.py", line 137, in match
    raise error
parsimonious.exceptions.ParseError: Rule 'type' didn't match at '
        )' (line 1, column 2).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/utils/solidity.py", line 185, in normalize_function_signature
    args_tuple_type = parse_type(normalize_type(f'({args})'))
  File "/home/web/venv/lib/python3.7/site-packages/eth_abi/grammar.py", line 125, in parse
    raise ParseError(e.text, e.pos, e.expr)
eth_abi.exceptions.ParseError: Parse error at '
    ' (column 2) in type string '(
        )'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/web/venv/lib/python3.7/site-packages/huey/consumer.py", line 151, in process_task
    self.huey.execute(task)
  File "/home/web/venv/lib/python3.7/site-packages/huey/api.py", line 266, in execute
    result = task.execute()
  File "/home/web/venv/lib/python3.7/site-packages/huey/api.py", line 560, in execute
    return func(*args, **kwargs)
  File "/home/web/venv/lib/python3.7/site-packages/huey/contrib/djhuey/__init__.py", line 91, in inner
    return fn(*args, **kwargs)
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/registry/tasks.py", line 32, in perform_github_import
    Signature.import_from_solidity_file(solidity_file)
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/registry/models.py", line 109, in import_from_solidity_file
    return cls.import_from_solidity_code(code)
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/registry/models.py", line 102, in import_from_solidity_code
    for raw_signature in function_signatures
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/registry/models.py", line 102, in <listcomp>
    for raw_signature in function_signatures
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/registry/models.py", line 87, in import_from_raw_text_signature
    text_signature = normalize_function_signature(raw_function_signature)
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/utils/solidity.py", line 189, in normalize_function_signature
    arg_types = ','.join(get_arg_types(args))
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/utils/solidity.py", line 169, in get_arg_types
    types = [p.strip().split(maxsplit=1)[0] for p in parts]
  File "/home/web/ethereum-function-signature-registry/func_sig_registry/utils/solidity.py", line 169, in <listcomp>
    types = [p.strip().split(maxsplit=1)[0] for p in parts]
IndexError: list index out of range