angr/archinfo

Confusing error message when pyvex fails to import

cdisselkoen opened this issue · 5 comments

If pyvex fails to import, archinfo/arch.py sets _pyvex to None (line 13). The rest of the code is very careful to check that _pyvex is not None before using it, except line 188, which references _pyvex without first checking that it is not None. As a result, a failed import of pyvex gives the error message 'AttributeError: 'NoneType' object has no attribute 'vex_ffi' on line 188, which is a very confusing way to say "pyvex failed to import". I'm not sure whether the proper fix is to simply move the two lines 188-189 inside the if-block which begins at line 191? or if something more complicated is needed. If the former, I'm happy to put up a PR.

It is indeed a bug. I would move and _pyvex is not None four two lines up. PR welcome!

Also, it would be great if you can add a test case to test the import of archinfo without pyvex.

Actually, https://medium.com/python-pandemonium/how-to-test-your-imports-1461c1113be1 seems to have a solution for how to create a test case. I'm on it

... wait, where are the tests for this repo?

Great. We never bother to write any test cases for archinfo. You may create a tests directory and drop your test file there. We will add it to our CI later. Thanks in advance!