@lukash
Latest commit 083b1e7 Dec 19, 2019 History
For C API functions that have a GError argument to allow reporting an
error, catch the libdnf::Error exception and convert it to GError.

This is a rather incomplete solution, as there are functions that can
get an exception but don't have the GError argument, so it is not
possible to report an error and therefore it is mostly unclear how they
should behave in case of an error. I've left those functions as they
are, meaning an exception being thrown from them will still cause a
terminate().

Also, some of the functions that are being wrapped with the try-catch have a
cleanup label and use gotos. I have kept those as they are, which means
strictly speaking the cleanup is now wrong. My goal was to handle the
exceptions uniformly and consistently and to solve this properly, I would have to
convert the goto cleanups to a C++ style cleanup (using RAII). C-style error handling
doesn't mix well with C++ and any other solution would have to be
case-specific (and need time to figure it out).

The difference for these cases is that in case of only exceptions based
on libdnf::Error (an expected error we want to report to the user), the
cleanup won't be correct. However, we still had an error which is most
likely fatal and the program will terminate anyway. Practicaly the only
difference should be the user will get an error message instead of a crash.

Closes: #866
Approved by: jrohel
11 contributors

Users who have contributed to this file

@jrohel @jlebon @jdieter @kontura @cgwalters @dmnks @lukash @kalev @jwakely @j-mracek @dmach