From cee9f740e4a591bc5b1f2dc023b92a3537dbdc63 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 25 Mar 2024 14:19:45 +0100 Subject: [PATCH] filter-chain: improve json parsing error reporting Warn when an invalid key is parsed instead of silently ignoring it. --- src/modules/module-filter-chain.c | 33 ++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index b0d5888ba..92e9952d0 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -1955,8 +1955,11 @@ static int parse_link(struct graph *graph, struct spa_json *json) return -EINVAL; } } - else if (spa_json_next(json, &val) < 0) - break; + else { + pw_log_error("unexpected link key '%s'", key); + if (spa_json_next(json, &val) < 0) + break; + } } def_out_node = spa_list_first(&graph->node_list, struct node, link); def_in_node = spa_list_last(&graph->node_list, struct node, link); @@ -2066,8 +2069,11 @@ static int parse_volume(struct graph *graph, struct spa_json *json, bool capture return -EINVAL; } } - else if (spa_json_next(json, &val) < 0) - break; + else { + pw_log_error("unexpected volume key '%s'", key); + if (spa_json_next(json, &val) < 0) + break; + } } if (capture) def_control = spa_list_first(&graph->node_list, struct node, link); @@ -2162,12 +2168,18 @@ static int load_node(struct graph *graph, struct spa_json *json) have_config = true; if (spa_json_next(json, &val) < 0) break; - } else if (spa_json_next(json, &val) < 0) - break; + } else { + pw_log_warn("unexpected node key '%s'", key); + if (spa_json_next(json, &val) < 0) + break; + } } - if (spa_streq(type, "builtin")) snprintf(plugin, sizeof(plugin), "%s", "builtin"); + else if (spa_streq(type, "")) { + pw_log_error("missing plugin type"); + return -EINVAL; + } pw_log_info("loading type:%s plugin:%s label:%s", type, plugin, label); @@ -2756,8 +2768,11 @@ static int load_graph(struct graph *graph, struct pw_properties *props) return -EINVAL; } ppvolumes = &pvolumes; - } else if (spa_json_next(&it[1], &val) < 0) - break; + } else { + pw_log_warn("unexpected graph key '%s'", key); + if (spa_json_next(&it[1], &val) < 0) + break; + } } if (pnodes == NULL) { pw_log_error("filter.graph is missing a nodes array");