From: Sebastian Harl Date: Thu, 28 Nov 2013 17:17:28 +0000 (+0100) Subject: store: Let tojson() embed errors into JSON rather than aborting. X-Git-Tag: sysdb-0.1.0~336^2~1 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=c73181fc7b863f05d89c1879bcc9b7c24ad155cf store: Let tojson() embed errors into JSON rather than aborting. --- diff --git a/src/core/store.c b/src/core/store.c index be307c5..587c527 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -487,9 +487,11 @@ sdb_store_tojson(sdb_strbuf_t *buf) char errbuf[1024]; sdb_log(SDB_LOG_ERR, "store: Failed to retrieve attributes: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); - break; + sdb_strbuf_append(buf, "{\"error\": \"failed to retrieve " + "attributes: %s\"}", errbuf); } + /* has_next returns false if the iterator is NULL */ while (sdb_llist_iter_has_next(attr_iter)) { sdb_attribute_t *attr = SDB_ATTR(sdb_llist_iter_get_next(attr_iter)); assert(attr); @@ -512,7 +514,8 @@ sdb_store_tojson(sdb_strbuf_t *buf) char errbuf[1024]; sdb_log(SDB_LOG_ERR, "store: Failed to retrieve services: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); - break; + sdb_strbuf_append(buf, "{\"error\": \"failed to retrieve " + "services: %s\"}", errbuf); } while (sdb_llist_iter_has_next(svc_iter)) { diff --git a/src/include/core/store.h b/src/include/core/store.h index bef29ba..bc4de10 100644 --- a/src/include/core/store.h +++ b/src/include/core/store.h @@ -101,7 +101,7 @@ sdb_store_service(const char *hostname, const char *name, /* * sdb_store_tojson: - * Serialize the entire store to JSON and write the result to the specified + * Serialize the entire store to JSON and append the result to the specified * buffer. * * Returns: