Skip to content
This repository has been archived by the owner on May 31, 2020. It is now read-only.

Error while compiling urllib3 dependency #726

Open
ghost opened this issue Jan 26, 2018 · 3 comments
Open

Error while compiling urllib3 dependency #726

ghost opened this issue Jan 26, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 26, 2018

$ python --version
Python version: 3.6.4

$ voc --version
voc 0.1.5
:buildPythonDebug
Compiling app_packages/urllib3/filepost.py ...
Traceback (most recent call last):
Compiling app_packages/urllib3/__init__.py ...
  File "/usr/lib/python3.6/site-packages/voc-0.1.5-py3.6.egg/voc/python/ast.py", line 160, in visit
Compiling app_packages/urllib3/poolmanager.py ...
    super().visit(node)
Compiling app_packages/urllib3/connection.py ...
  File "/usr/lib/python3.6/ast.py", line 253, in visit
Compiling app_packages/urllib3/response.py ...
    return visitor(node)

  File "/usr/lib/python3.6/site-packages/voc-0.1.5-py3.6.egg/voc/python/ast.py", line 49, in dec
Problem occurred in urllib3/response.py
    fn(self, node, *args, **kwargs)
Node: ExceptHandler(type=Attribute(value=Name(id='zlib', ctx=Load(), lineno=46, col_offset=15), attr='error', ctx=Load(), lineno=46, col_offset=15), name=None, body=[
  File "/usr/lib/python3.6/site-packages/voc-0.1.5-py3.6.egg/voc/python/ast.py", line 2310, in visit_ExceptHandler
    Assign(targets=[
    exception = self.full_classref(node.type.id, default_prefix='org.python.exceptions')
        Attribute(value=Name(id='self', ctx=Load(), lineno=47, col_offset=12), attr='_first_try', ctx=Store(), lineno=47, col_offset=12),
AttributeError: 'Attribute' object has no attribute 'id'
      ], value=NameConstant(value=False, lineno=47, col_offset=30), lineno=47, col_offset=12),
    Assign(targets=[
        Attribute(value=Name(id='self', ctx=Load(), lineno=48, col_offset=12), attr='_obj', ctx=Store(), lineno=48, col_offset=12),
      ], value=Call(func=Attribute(value=Name(id='zlib', ctx=Load(), lineno=48, col_offset=24), attr='decompressobj', ctx=Load(), lineno=48, col_offset=24), args=[
        UnaryOp(op=USub(), operand=Attribute(value=Name(id='zlib', ctx=Load(), lineno=48, col_offset=44), attr='MAX_WBITS', ctx=Load(), lineno=48, col_offset=44), lineno=48, col_offset=43),
      ], keywords=[], lineno=48, col_offset=24), lineno=48, col_offset=12),
    Try(body=[
        Return(value=Call(func=Attribute(value=Name(id='self', ctx=Load(), lineno=50, col_offset=23), attr='decompress', ctx=Load(), lineno=50, col_offset=23), args=[
            Attribute(value=Name(id='self', ctx=Load(), lineno=50, col_offset=39), attr='_data', ctx=Load(), lineno=50, col_offset=39),
          ], keywords=[], lineno=50, col_offset=23), lineno=50, col_offset=16),
      ], handlers=[], orelse=[], finalbody=[
        Assign(targets=[
            Attribute(value=Name(id='self', ctx=Load(), lineno=52, col_offset=16), attr='_data', ctx=Store(), lineno=52, col_offset=16),
          ], value=NameConstant(value=None, lineno=52, col_offset=29), lineno=52, col_offset=16),
      ], lineno=49, col_offset=12),
  ], lineno=46, col_offset=8)
:buildPythonDebug FAILED
@eliasdorneles
Copy link
Collaborator

Yeah, this is a known bug.

This is a pretty interesting issue, I've tried tackling it before but ended up not going too deep.
Basically, the main thing here is that Python accepts any expression as an exception type to be caught by the except clause.

The current implementation of the except clause handler in VOC doesn't yet support any Python expressions (urllib3.response is doing zlib.error).

I believe the way to fix this is to have two different ways of handling exceptions, depending on what's coming after the except: if it's one of the exceptions from the stdlib, then we can use the current approach (which is nice because it will register the proper exception type in the JVM bytecode exception table).
If it's not, then we need to do a block that catch all possible exceptions, dynamically type-check to see if it matches the type specified by the expression and then decide to handle it (i.e. run code inside of the except block) or to re-raise it if types do not match.

@uranusjr
Copy link
Contributor

Semi-related question, would zlib.error end up inside JVM’s exception table after compilation? Can it? Because that way we can get its class ref here (is this possible?) and use it instead.

@eliasdorneles
Copy link
Collaborator

eliasdorneles commented Jan 26, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants