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

Wrap gi.require with assert in class.lua and ffi.lua #319

Merged
merged 1 commit into from
Jun 15, 2024

Conversation

stefano-m
Copy link
Contributor

Fixes #71

Calling gi.require may not always succeed. If we do not wrap it in an assert, we will get confusing error messages.

For example, a failure in lgi/ffi.lua would look like:

attempt to index local 'gobject' (a boolean value)

wrapping gi.require with assert instead would show a more informative message:

Typelib file for namespace 'win32', version '1.0' not found

This change updates both lgi/class.lua and lgi/ffi.lua which appear to be the only two files in the codebase that do not wrap gi.require with an assert.

A practical example where this would have been useful is NixOS/nixpkgs#139159 (comment)

I actually managed to figure out the issue with NixOS using this patch.

Thanks for developing and maintaining lgi!

Fixes lgi-devs#71

Calling gi.require may not always succeed. If we do not wrap it in an `assert`,
we will get confusing error messages.

For example, a failure in `lgi/ffi.lua` would look like:

    attempt to index local 'gobject' (a boolean value)

wrapping `gi.require` with `assert` instead would show a more informative
message:

    Typelib file for namespace 'win32', version '1.0' not found

This change updates both `lgi/class.lua` and `lgi/ffi.lua` which appear to be
the only two files in the codebase that do not wrap `gi.require` with an
`assert`.
@psychon
Copy link
Collaborator

psychon commented Jun 15, 2024

Seems convincing enough. Thanks!

Thanks for developing and maintaining lgi!

Sorry for not doing either of that. 🙈

@psychon psychon merged commit e06ad94 into lgi-devs:master Jun 15, 2024
5 checks passed
@stefano-m stefano-m deleted the wrap_assert_gi_require branch August 3, 2024 20:22
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.

lgi/ffi.lua should wrap gi.require() in assert()
2 participants