GNOME Bugzilla – Bug 689452
G_SPAWN_EXIT_ERROR not (nicely) introspectable
Last modified: 2018-01-24 19:25:59 UTC
g_spawn_check_exit_status() and its error domain G_SPAWN_EXIT_ERROR were introduced in: https://bugzilla.gnome.org/show_bug.cgi?id=679691 First, an ugly aspect of this is that the function can throw two separate domains that you have to handle. The next problem is G_SPAWN_EXIT_ERROR has no corresponding enumeration for error codes, which means introspection won't have nice GError handling for it. This is what you have to do in gjs at the moment if you want to catch a spawn error and just extract the message: try { GLib.spawn_check_exit_status(estatus); success = true; } catch (e) { if (e.matches(GLib.SpawnError, GLib.SpawnError.Failed || e.domain == GLib.spawn_exit_error_quark()) errorMsg = e.message(); else throw e; } The way we stuff the exit code into the error code means that if we wanted to have a corresponding enumeration, it'd need to have 255 members =/ Kind of ugly...
(In reply to comment #0) > First, an ugly aspect of this is that the function can throw two separate > domains that you have to handle. I don't consider that ugly. You wouldn't really need error domains if every function only returned errors from a single domain. It's true that not many functions in glib currently return errors from multiple domains, but that's just because not many functions in glib are complicated enough that they can fail in multiple categories of ways. But, eg, g_tls_connection_handshake() can can fail due to either I/O problems or due to certificate-related problems, so it can throw either G_IO_ERROR or G_TLS_ERROR. > if (e.matches(GLib.SpawnError, GLib.SpawnError.Failed) || > e.domain == GLib.spawn_exit_error_quark()) That's ugly though... Making the second argument to GLib.Error.matches() be optional would be one fix...
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]
I don't think there's anything to fix in g-i. Fixing the ugliness of g_spawn_exit_error_quark() should be opened as a bug in GLib.