Our current handling of errors is rather naive. All we do is print stuff on stderr and return false. Once hirte is in production I think we want something more manageable. For example, we should probably have some minimal helpers for logging issues that have a log level which can be tweaked during testing via the configuration. And, it should probably go to the systemd journal at least when in production (although during testing, being able to get it to stderr is probably nice too).
We also shoud probably pick up the systemd error reporting mechanism of returning -errno
style integers instead of just true/false for "success"/"error". That way callers can get at least some more nformation on exactly what failed. In many cases we already call into systemd APIs which can give this info. For example:
bool node_export(Node *node) {
Manager *manager = node->manager;
int r = sd_bus_add_object_vtable(
manager->user_dbus,
&node->export_slot,
node->object_path,
NODE_INTERFACE,
node_vtable,
node);
if (r < 0) {
fprintf(stderr, "Failed to add node vtable: %s\n", strerror(-r));
return false;
}
return true;
}
int node_export(Node *node) {
Manager *manager = node->manager;
int r = sd_bus_add_object_vtable(
manager->user_dbus,
&node->export_slot,
node->object_path,
NODE_INTERFACE,
node_vtable,
node);
if (r < 0) {
hirte_log(HIRTE_LOG_WARNING, "Failed to add node vtable: %s\n", strerror(-r));
}
return r;
}