Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing error message if libgpiod can't be opened #8

Open
habnabit opened this issue May 31, 2021 · 1 comment
Open

Confusing error message if libgpiod can't be opened #8

habnabit opened this issue May 31, 2021 · 1 comment

Comments

@habnabit
Copy link

try:
lib = ffi.dlopen("libgpiod.so.2")
except OSError:
lib = ffi.dlopen("c") # workaround if we're only building docs

If the dlopen fails, the original error is lost and that makes debugging very annoying. As you can see in this traceback, the error didn't happen on import and the message gives no indication about why it failed:

Traceback (most recent call last):
  File "examples/line_echo.py", line 26, in <module>
    anyio.run(main, backend="trio")
  File "/home/pi/ve/lib/python3.7/site-packages/anyio/_core/_eventloop.py", line 56, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "/home/pi/ve/lib/python3.7/site-packages/trio/_core/_run.py", line 1932, in run
    raise runner.main_task_outcome.error
  File "examples/line_echo.py", line 18, in main
    with gpio.Chip(0) as c:
  File "/home/pi/ve/lib/python3.7/site-packages/asyncgpio/gpio.py", line 39, in __enter__
    self._chip = gpio.lib.gpiod_chip_open_by_number(self._num)
  File "/home/pi/ve/lib/python3.7/site-packages/cffi/api.py", line 912, in __getattr__
    make_accessor(name)
  File "/home/pi/ve/lib/python3.7/site-packages/cffi/api.py", line 908, in make_accessor
    accessors[name](name)
  File "/home/pi/ve/lib/python3.7/site-packages/cffi/api.py", line 838, in accessor_function
    value = backendlib.load_function(BType, name)
AttributeError: function/symbol 'gpiod_chip_open_by_number' not found in library 'libc.so.6': /lib/arm-linux-gnueabihf/libc.so.6: undefined symbol: gpiod_chip_open_by_number

If this is really just a workaround for docs, maybe better to include e.g. if not os.environ.get('_ASYNCGPIO_BUILDING_DOCS'): raise in the except stanza?

@smurfix
Copy link
Collaborator

smurfix commented May 31, 2021

Thanks for the report. You're right. Pull requests welcome. ;-)

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

No branches or pull requests

2 participants