[Gtk3] Can `Gtk.IconTheme.load_icon` throw GError?

Hello, I want to know if Gtk.IconTheme.load_icon can throw error, and if so, which kind of error could be thrown in what kind of cases.

I am making a program which displays icons of other applications. Clearly, sometimes the icon would not be available at the desired directories. (Like when it is from snap) - I want to show default icon in that case. Now, I was operating under the assumption that in case of typical failure (like missing icon), the procedure would simply return NULL instead of an error. However, it seems like it can throw GError, though the documentation does not talk about the possible errors.

In fact, I am getting error messages like

Icon 'Zulip1_32-panel' not present in theme Yaru (0)

(For some weird reason, its header seems to be stripped off)
Could this be caused by GError thrown from the procedure?
Also, can I know about the possible GErrors the procedure could throw?

The code is here: https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/gtkicontheme.c#L2257. It does some checks and then calls gtk_icon_theme_load_icon_for_scale (), which is what sets the error. That code is underneath. That in turn calls gtk_icon_theme_lookup_icon_for_scale () and gtk_icon_info_load_icon () and will throw error “Icon ‘%s’ not present in theme %s” if the lookup fails or error "Failed to load %s: " it the load fails.

So it errors rather than giving NULL? Oh no, I have to change my code ASAP.

Which programming language are you using?

The method will return NULL and set the given GError argument. Depending on the language binding you’re using, the error may be turned into an exception or any other recoverable error mechanism the language has.

The only time a NULL value will be returned without setting the GError argument is in case of failures for a precondition validation, as those are programmer errors and will print out a critical warning at the call site.


Thank you, it seems like GError was being thrown. Corrected the expectation, Fixed the bug.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.