printers BUGFIX actually return an error on printing error
diff --git a/src/printer.h b/src/printer.h
index c85be70..331d0af 100644
--- a/src/printer.h
+++ b/src/printer.h
@@ -70,7 +70,7 @@
int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
int xml_print_data(struct lyout *out, const struct lyd_node *root, int options);
-void xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
+int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
/**
* get know if the node is supposed to be printed according to the specified with-default mode
diff --git a/src/printer_json.c b/src/printer_json.c
index 0d51484..43210e5 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -27,8 +27,8 @@
#define INDENT ""
#define LEVEL (level*2)
-static void json_print_nodes(struct lyout *out, int level, const struct lyd_node *root, int withsiblings, int toplevel,
- int options);
+static int json_print_nodes(struct lyout *out, int level, const struct lyd_node *root, int withsiblings, int toplevel,
+ int options);
static int
json_print_string(struct lyout *out, const char *text)
@@ -63,7 +63,7 @@
return n + 2;
}
-static void
+static int
json_print_attrs(struct lyout *out, int level, const struct lyd_node *node, const struct lys_module *wdmod)
{
struct lyd_attr *attr;
@@ -127,13 +127,16 @@
default:
/* error */
ly_print(out, "\"(!error!)\"");
+ return EXIT_FAILURE;
}
ly_print(out, "%s%s", attr->next ? "," : "", (level ? "\n" : ""));
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_leaf(struct lyout *out, int level, const struct lyd_node *node, int onlyvalue, int toplevel, int options)
{
struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *)node, *iter;
@@ -208,7 +211,7 @@
if (!type) {
/* error */
ly_print(out, "\"(!error!)\"");
- return;
+ return EXIT_FAILURE;
}
datatype = type->base;
} else {
@@ -223,6 +226,7 @@
default:
/* error */
ly_print(out, "\"(!error!)\"");
+ return EXIT_FAILURE;
}
/* print attributes as sibling leafs */
@@ -234,14 +238,16 @@
ly_print(out, ",%s%*s\"@%s\":%s{%s", (level ? "\n" : ""), LEVEL, INDENT, node->schema->name,
(level ? " " : ""), (level ? "\n" : ""));
}
- json_print_attrs(out, (level ? level + 1 : level), node, wdmod);
+ if (json_print_attrs(out, (level ? level + 1 : level), node, wdmod)) {
+ return EXIT_FAILURE;
+ }
ly_print(out, "%*s}", LEVEL, INDENT);
}
- return;
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_container(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
const char *schema;
@@ -258,20 +264,26 @@
}
if (node->attr) {
ly_print(out, "%*s\"@\":%s{%s", LEVEL, INDENT, (level ? " " : ""), (level ? "\n" : ""));
- json_print_attrs(out, (level ? level + 1 : level), node, NULL);
+ if (json_print_attrs(out, (level ? level + 1 : level), node, NULL)) {
+ return EXIT_FAILURE;
+ }
ly_print(out, "%*s}", LEVEL, INDENT);
if (node->child) {
ly_print(out, ",%s", (level ? "\n" : ""));
}
}
- json_print_nodes(out, level, node->child, 1, 0, options);
+ if (json_print_nodes(out, level, node->child, 1, 0, options)) {
+ return EXIT_FAILURE;
+ }
if (level) {
level--;
}
ly_print(out, "%*s}", LEVEL, INDENT);
+
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_leaf_list(struct lyout *out, int level, const struct lyd_node *node, int is_list, int toplevel, int options)
{
const char *schema = NULL;
@@ -293,7 +305,7 @@
if (flag_empty) {
ly_print(out, "%snull", (level ? " " : ""));
- return;
+ return EXIT_SUCCESS;
}
ly_print(out, "%s[%s", (level ? " " : ""), (level ? "\n" : ""));
@@ -313,14 +325,18 @@
}
if (list->attr) {
ly_print(out, "%*s\"@\":%s{%s", LEVEL, INDENT, (level ? " " : ""), (level ? "\n" : ""));
- json_print_attrs(out, (level ? level + 1 : level), list, NULL);
+ if (json_print_attrs(out, (level ? level + 1 : level), list, NULL)) {
+ return EXIT_FAILURE;
+ }
if (list->child) {
ly_print(out, "%*s},%s", LEVEL, INDENT, (level ? "\n" : ""));
} else {
ly_print(out, "%*s}", LEVEL, INDENT);
}
}
- json_print_nodes(out, level, list->child, 1, 0, options);
+ if (json_print_nodes(out, level, list->child, 1, 0, options)) {
+ return EXIT_FAILURE;
+ }
if (level) {
--level;
}
@@ -331,7 +347,9 @@
} else {
/* leaf-list print */
ly_print(out, "%*s", LEVEL, INDENT);
- json_print_leaf(out, level, list, 1, toplevel, options);
+ if (json_print_leaf(out, level, list, 1, toplevel, options)) {
+ return EXIT_FAILURE;
+ }
if (list->attr) {
flag_attrs = 1;
}
@@ -363,7 +381,9 @@
for (list = node; list; ) {
if (list->attr) {
ly_print(out, "%*s{%s", LEVEL, INDENT, (level ? " " : ""));
- json_print_attrs(out, 0, list, NULL);
+ if (json_print_attrs(out, 0, list, NULL)) {
+ return EXIT_FAILURE;
+ }
ly_print(out, "%*s}", LEVEL, INDENT);
} else {
ly_print(out, "%*snull", LEVEL, INDENT);
@@ -380,9 +400,11 @@
}
ly_print(out, "%s%*s]", (level ? "\n" : ""), LEVEL, INDENT);
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_anyxml(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
struct lyd_node_anydata *any = (struct lyd_node_anydata *)node;
@@ -406,7 +428,9 @@
isobject = 1;
ly_print(out, level ? "{\n" : "{");
/* do not print any default values nor empty containers */
- json_print_nodes(out, level, any->value.tree, 1, 0, LYP_WITHSIBLINGS | (options & ~LYP_NETCONF));
+ if (json_print_nodes(out, level, any->value.tree, 1, 0, LYP_WITHSIBLINGS | (options & ~LYP_NETCONF))) {
+ return EXIT_FAILURE;
+ }
break;
case LYD_ANYDATA_JSON:
isobject = 1;
@@ -441,9 +465,11 @@
if (isobject) {
ly_print(out, "%*s}", LEVEL, INDENT);
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_anydata(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
const char *schema = NULL;
@@ -463,7 +489,9 @@
switch (any->value_type) {
case LYD_ANYDATA_DATATREE:
/* do not print any default values nor empty containers */
- json_print_nodes(out, level, any->value.tree, 1, 0, LYP_WITHSIBLINGS | (options & LYP_FORMAT));
+ if (json_print_nodes(out, level, any->value.tree, 1, 0, LYP_WITHSIBLINGS | (options & LYP_FORMAT))) {
+ return EXIT_FAILURE;
+ }
break;
case LYD_ANYDATA_JSON:
if (any->value.str) {
@@ -485,24 +513,29 @@
ly_print(out, ",%s%*s\"@%s\":%s{%s", (level ? "\n" : ""), LEVEL, INDENT, node->schema->name,
(level ? " " : ""), (level ? "\n" : ""));
}
- json_print_attrs(out, (level ? level + 1 : level), node, NULL);
+ if (json_print_attrs(out, (level ? level + 1 : level), node, NULL)) {
+ return EXIT_FAILURE;
+ }
ly_print(out, "%*s}", LEVEL, INDENT);
}
-
if (level) {
level--;
}
ly_print(out, "%*s}", LEVEL, INDENT);
+
+ return EXIT_SUCCESS;
}
-static void
+static int
json_print_nodes(struct lyout *out, int level, const struct lyd_node *root, int withsiblings, int toplevel, int options)
{
+ int ret = EXIT_SUCCESS;
const struct lyd_node *node, *iter;
LY_TREE_FOR(root, node) {
if (!lyd_wd_toprint(node, options)) {
+ /* wd says do not print */
continue;
}
@@ -515,14 +548,14 @@
/* print the previous comma */
ly_print(out, ",%s", (level ? "\n" : ""));
}
- json_print_container(out, level, node, toplevel, options);
+ ret = json_print_container(out, level, node, toplevel, options);
break;
case LYS_LEAF:
if (node->prev->next) {
/* print the previous comma */
ly_print(out, ",%s", (level ? "\n" : ""));
}
- json_print_leaf(out, level, node, 0, toplevel, options);
+ ret = json_print_leaf(out, level, node, 0, toplevel, options);
break;
case LYS_LEAFLIST:
case LYS_LIST:
@@ -543,7 +576,7 @@
}
/* print the list/leaflist */
- json_print_leaf_list(out, level, node, node->schema->nodetype == LYS_LIST ? 1 : 0, toplevel, options);
+ ret = json_print_leaf_list(out, level, node, node->schema->nodetype == LYS_LIST ? 1 : 0, toplevel, options);
}
break;
case LYS_ANYXML:
@@ -551,17 +584,18 @@
/* print the previous comma */
ly_print(out, ",%s", (level ? "\n" : ""));
}
- json_print_anyxml(out, level, node, toplevel, options);
+ ret = json_print_anyxml(out, level, node, toplevel, options);
break;
case LYS_ANYDATA:
if (node->prev->next) {
/* print the previous comma */
ly_print(out, ",%s", (level ? "\n" : ""));
}
- json_print_anydata(out, level, node, toplevel, options);
+ ret = json_print_anydata(out, level, node, toplevel, options);
break;
default:
LOGINT;
+ ret = EXIT_FAILURE;
break;
}
@@ -572,6 +606,8 @@
if (root && level) {
ly_print(out, "\n");
}
+
+ return ret;
}
int
@@ -618,7 +654,9 @@
}
/* content */
- json_print_nodes(out, level, root, options & LYP_WITHSIBLINGS, 1, options);
+ if (json_print_nodes(out, level, root, options & LYP_WITHSIBLINGS, 1, options)) {
+ return EXIT_FAILURE;
+ }
if (action_input) {
if (level) {
diff --git a/src/printer_xml.c b/src/printer_xml.c
index 5d98556..008a6b5 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -126,7 +126,7 @@
}
}
-static void
+static int
xml_print_attrs(struct lyout *out, const struct lyd_node *node, int options)
{
struct lyd_attr *attr;
@@ -166,7 +166,7 @@
if (!xml_expr) {
/* error */
ly_print(out, "\"(!error!)\"");
- return;
+ return EXIT_FAILURE;
}
for (i = 0; i < ns_count; ++i) {
@@ -223,7 +223,7 @@
if (!xml_expr) {
/* error */
ly_print(out, "(!error!)");
- return;
+ return EXIT_FAILURE;
}
for (i = 0; i < ns_count; ++i) {
@@ -243,6 +243,7 @@
default:
/* error */
ly_print(out, "(!error!)");
+ return EXIT_FAILURE;
}
ly_print(out, "\"");
@@ -251,9 +252,11 @@
lydict_remove(node->schema->module->ctx, xml_expr);
}
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
xml_print_leaf(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
const struct lyd_node_leaf_list *leaf = (struct lyd_node_leaf_list *)node, *iter;
@@ -278,7 +281,9 @@
xml_print_ns(out, node, options);
}
- xml_print_attrs(out, node, options);
+ if (xml_print_attrs(out, node, options)) {
+ return EXIT_FAILURE;
+ }
datatype = leaf->value_type & LY_DATA_TYPE_MASK;
printvalue:
switch (datatype) {
@@ -330,7 +335,7 @@
if (!xml_expr) {
/* error */
ly_print(out, "\"(!error!)\"");
- return;
+ return EXIT_FAILURE;
}
for (i = 0; i < ns_count; ++i) {
@@ -360,7 +365,7 @@
if (!type) {
/* error */
ly_print(out, "\"(!error!)\"");
- return;
+ return EXIT_FAILURE;
}
datatype = type->base;
} else {
@@ -375,14 +380,17 @@
default:
/* error */
ly_print(out, "\"(!error!)\"");
+ return EXIT_FAILURE;
}
if (level) {
ly_print(out, "\n");
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
xml_print_container(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
struct lyd_node *child;
@@ -400,22 +408,28 @@
xml_print_ns(out, node, options);
}
- xml_print_attrs(out, node, options);
+ if (xml_print_attrs(out, node, options)) {
+ return EXIT_FAILURE;
+ }
if (!node->child) {
ly_print(out, "/>%s", level ? "\n" : "");
- return;
+ return EXIT_SUCCESS;
}
ly_print(out, ">%s", level ? "\n" : "");
LY_TREE_FOR(node->child, child) {
- xml_print_node(out, level ? level + 1 : 0, child, 0, options);
+ if (xml_print_node(out, level ? level + 1 : 0, child, 0, options)) {
+ return EXIT_FAILURE;
+ }
}
ly_print(out, "%*s</%s>%s", LEVEL, INDENT, node->schema->name, level ? "\n" : "");
+
+ return EXIT_SUCCESS;
}
-static void
+static int
xml_print_list(struct lyout *out, int level, const struct lyd_node *node, int is_list, int toplevel, int options)
{
struct lyd_node *child;
@@ -434,16 +448,20 @@
if (toplevel) {
xml_print_ns(out, node, options);
}
- xml_print_attrs(out, node, options);
+ if (xml_print_attrs(out, node, options)) {
+ return EXIT_FAILURE;
+ }
if (!node->child) {
ly_print(out, "/>%s", level ? "\n" : "");
- return;
+ return EXIT_SUCCESS;
}
ly_print(out, ">%s", level ? "\n" : "");
LY_TREE_FOR(node->child, child) {
- xml_print_node(out, level ? level + 1 : 0, child, 0, options);
+ if (xml_print_node(out, level ? level + 1 : 0, child, 0, options)) {
+ return EXIT_FAILURE;
+ }
}
ly_print(out, "%*s</%s>%s", LEVEL, INDENT, node->schema->name, level ? "\n" : "");
@@ -451,9 +469,11 @@
/* leaf-list print */
xml_print_leaf(out, level, node, toplevel, options);
}
+
+ return EXIT_SUCCESS;
}
-static void
+static int
xml_print_anydata(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
char *buf;
@@ -472,7 +492,9 @@
if (toplevel) {
xml_print_ns(out, node, options);
}
- xml_print_attrs(out, node, options);
+ if (xml_print_attrs(out, node, options)) {
+ return EXIT_FAILURE;
+ }
if (!(void*)any->value.tree || (any->value_type == LYD_ANYDATA_CONSTSTRING && !any->value.str[0])) {
/* no content */
ly_print(out, "/>%s", level ? "\n" : "");
@@ -490,7 +512,9 @@
ly_print(out, "\n");
}
LY_TREE_FOR(any->value.tree, iter) {
- xml_print_node(out, level ? level + 1 : 0, iter, 0, (options & ~(LYP_WITHSIBLINGS | LYP_NETCONF)));
+ if (xml_print_node(out, level ? level + 1 : 0, iter, 0, (options & ~(LYP_WITHSIBLINGS | LYP_NETCONF)))) {
+ return EXIT_FAILURE;
+ }
}
}
break;
@@ -519,13 +543,18 @@
/* closing tag */
ly_print(out, "</%s>%s", node->schema->name, level ? "\n" : "");
}
+
+ return EXIT_SUCCESS;
}
-void
+int
xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options)
{
+ int ret = EXIT_SUCCESS;
+
if (!lyd_wd_toprint(node, options)) {
- return;
+ /* wd says do not print */
+ return EXIT_SUCCESS;
}
switch (node->schema->nodetype) {
@@ -533,25 +562,28 @@
case LYS_RPC:
case LYS_ACTION:
case LYS_CONTAINER:
- xml_print_container(out, level, node, toplevel, options);
+ ret = xml_print_container(out, level, node, toplevel, options);
break;
case LYS_LEAF:
- xml_print_leaf(out, level, node, toplevel, options);
+ ret = xml_print_leaf(out, level, node, toplevel, options);
break;
case LYS_LEAFLIST:
- xml_print_list(out, level, node, 0, toplevel, options);
+ ret = xml_print_list(out, level, node, 0, toplevel, options);
break;
case LYS_LIST:
- xml_print_list(out, level, node, 1, toplevel, options);
+ ret = xml_print_list(out, level, node, 1, toplevel, options);
break;
case LYS_ANYXML:
case LYS_ANYDATA:
- xml_print_anydata(out, level, node, toplevel, options);
+ ret = xml_print_anydata(out, level, node, toplevel, options);
break;
default:
LOGINT;
+ ret = EXIT_FAILURE;
break;
}
+
+ return ret;
}
int
@@ -601,7 +633,9 @@
/* content */
LY_TREE_FOR(root, node) {
- xml_print_node(out, level, node, 1, options);
+ if (xml_print_node(out, level, node, 1, options)) {
+ return EXIT_FAILURE;
+ }
if (!(options & LYP_WITHSIBLINGS)) {
break;
}