hughsie / libgusb

GUsb is a GObject wrapper for libusb1
GNU Lesser General Public License v2.1
25 stars 21 forks source link

Introspection does not detect most error domains #109

Open v1993 opened 1 year ago

v1993 commented 1 year ago

As of right now, only SourceError is properly declared as an error in generated files (see e.g. valadoc). This is a big issue for language bindings, since it removes the ability to (nicely) selectively catch exceptions from GUsb.

v1993 commented 1 year ago

I'm not quite sure if it's the cause of this issue, but it's worth noting that corresponding quark functions are appropriated by similarly named classes, e.g. Device.error_quark.

hughsie commented 1 year ago

Is it because the GUsbDevice error uses G_DEFINE_QUARK? the g_usb_source_error_quark() seems to be written out manually.

v1993 commented 1 year ago

That's plausible but would be pretty odd; G_DEFINE_QUARK is what official GLib docs recommend. It might have to do with header layout, although I'm not sure.

As an aside, I'm currently using a manually modified VAPI file on my end to work around this issue.

hughsie commented 1 year ago

As an aside, I'm currently using a manually modified VAPI file

Can you share what you're adding? I see

[CCode (cheader_filename = "gusb.h", cprefix = "G_USB_DEVICE_ERROR_", has_type_id = false)]
public enum DeviceError {
    INTERNAL,
    IO,
    TIMED_OUT,
    NOT_SUPPORTED,
    NO_DEVICE,
    NOT_OPEN,
    ALREADY_OPEN,
    CANCELLED,
    FAILED,
    PERMISSION_DENIED,
    BUSY,
    LAST
}
v1993 commented 1 year ago

All I do is replace enum with errordomain for affected domains. This is enough to get things working, although static quark() methods also, ideally, should be relocated there from classes they got stuck to.

hughsie commented 1 year ago

@v1993 If you can work out the fix I'm happy to review and then tag a new release.

v1993 commented 1 year ago

I'm currently bundling a modified vapi file with my application, which is good enough to get it working; hopefully will look into a proper fix later.