From c73181fc7b863f05d89c1879bcc9b7c24ad155cf Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Thu, 28 Nov 2013 18:17:28 +0100 Subject: [PATCH] store: Let tojson() embed errors into JSON rather than aborting. --- src/core/store.c | 7 +++++-- src/include/core/store.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) 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: -- 2.30.2