Skip to content

fix(backend): report why the _lbug extension failed to load - #72

Merged
adsharma merged 2 commits into
LadybugDB:mainfrom
shivanathd:fix/report-pybind-import-error
Oct 21, 2026
Merged

adsharma merged 2 commits into
LadybugDB:mainfrom
shivanathd:fix/report-pybind-import-error

Conversation

@shivanathd

Copy link
Copy Markdown
Contributor

Problem

When the bundled _lbug extension fails to import, get_pybind_module() swallows the ImportError, and ladybug falls back to the C API backend. The published wheels don't ship the C API shared library, so the user only sees this:

RuntimeError: Could not find lbug C API shared library. Set LBUG_C_API_LIB_PATH or download a shared lib ...

The real cause is hidden. On macOS it's usually a missing OpenSSL 3 runtime: the wheels link /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib, and they exclude OpenSSL on purpose (#724 in LadybugDB/ladybug, and the discussion in LadybugDB/ladybug#681). We hit this on an Apple-silicon Mac without Homebrew, running ladybug 0.19.0 under cognee. The message sent us looking for a C API library we never needed, when the fix was to install OpenSSL 3.

Change

  • _backend.get_pybind_module() keeps the ImportError.
  • The "Could not find lbug C API shared library" message now includes it. When the missing library is libssl or libcrypto, it adds a hint: install OpenSSL 3 (brew install openssl@3 on macOS).
  • No behaviour change otherwise: the same fallback order and the same exception type.

Example message after the change:

Could not find lbug C API shared library. Set LBUG_C_API_LIB_PATH or download a shared lib (e.g. run LBUG_LIB_KIND=shared bash scripts/download_lbug.sh). The bundled _lbug extension, which is tried first, failed to load: dlopen(.../_lbug.cpython-312-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/openssl@3/lib/libssl.3.dylib ... Ladybug needs an OpenSSL 3 runtime; on macOS, install it with `brew install openssl@3`.

Tests

test/test_backend_errors.py covers:

  • the message without a recorded import error (unchanged);
  • the message with an OpenSSL import error;
  • that a failed import is recorded.

ruff check passes on the changed files.

When the bundled _lbug extension fails to import, get_pybind_module()
swallows the ImportError and ladybug falls back to the C API backend. If
the C API shared library is not present either (the published wheels do
not ship it), the user only sees "Could not find lbug C API shared
library", which hides the real cause.

On macOS the usual cause is a missing OpenSSL 3 runtime: the wheels link
/opt/homebrew/opt/openssl@3/lib/libssl.3.dylib and exclude it on purpose.
Keep the ImportError and include it in the RuntimeError, with an OpenSSL
hint when libssl or libcrypto is the missing library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adsharma
adsharma merged commit 7bcc788 into LadybugDB:main Oct 21, 2026
2 of 6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants