Skip to content

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

Description

@habnabit

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions