We have landed a feature in GLib called an extended error domain, and it is available in GLib 2.67.2.
Extended error domains allow the developer to attach extra information to GError without either cluttering the error message string or creating a new error type or adding another out parameter to the function for error details. You can see how to do it by reading an example in GError documentation (search for "extend the GError type").
The API is not yet set in stone. It will freeze on 2021-02-13, so please try it out and send us feedback. Thanks.