Code

store: Let tojson() embed errors into JSON rather than aborting.
authorSebastian Harl <sh@tokkee.org>
Thu, 28 Nov 2013 17:17:28 +0000 (18:17 +0100)
committerSebastian Harl <sh@tokkee.org>
Thu, 28 Nov 2013 17:17:28 +0000 (18:17 +0100)
src/core/store.c
src/include/core/store.h

index be307c5829adb49f212a478f13cb4d34c82983e4..587c527a5185699efe18d104d65f499c12801145 100644 (file)
@@ -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)));
                        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);
                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)));
                        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)) {
                }
 
                while (sdb_llist_iter_has_next(svc_iter)) {
index bef29ba97add3241950af85303c158a27fcc4272..bc4de1090f6d4a95e980835cf7c4033002776e79 100644 (file)
@@ -101,7 +101,7 @@ sdb_store_service(const char *hostname, const char *name,
 
 /*
  * sdb_store_tojson:
 
 /*
  * 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:
  * buffer.
  *
  * Returns: