Add a way to hook into g_set_error()
For various historical and practical reasons, QEMU defines its own error C type[1]. With the recent !1304 (merged) extended error support, it seems we are not far off from being able to use GError
instead, which would clean up some code and help with glib-based library interoperability.
The one thing that is not currently possible is to be able to abort() or exit() when an error is set. In general, this is not a recommended programming practice, but done carefully, it is very convenient and I don't think we can convince QEMU developpers to remove that.
It allows for example such programming:
main {
initialize_this(.., &error_abort);
handle_options(.., &error_fatal);
..
}
If at any point an error is set during initialize_this
, the program will abort() with error details. Similarly for handle_options
, it will print the error and exit(1).
Can we consider a g_error_set_assigned_handler()
? The handlers would be called when an error is assigned (*err = new
).
With that, I think QEMU error code can be based on GError, and we can imagine a transition in the future.