diff --git a/spa/include/spa/utils/json-pod.h b/spa/include/spa/utils/json-pod.h index 579ae7a7a..615b97e2e 100644 --- a/spa/include/spa/utils/json-pod.h +++ b/spa/include/spa/utils/json-pod.h @@ -135,16 +135,32 @@ static inline int spa_json_to_pod_part(struct spa_pod_builder *b, uint32_t flags return 0; } -static inline int spa_json_to_pod(struct spa_pod_builder *b, uint32_t flags, - const struct spa_type_info *info, const char *value, int len) +static inline int spa_json_to_pod_checked(struct spa_pod_builder *b, uint32_t flags, + const struct spa_type_info *info, const char *value, int len, + struct spa_error_location *loc) { struct spa_json iter; const char *val; + int res; - if ((len = spa_json_begin(&iter, value, len, &val)) <= 0) - return -EINVAL; + if (loc) + spa_zero(*loc); - return spa_json_to_pod_part(b, flags, info->type, info, &iter, val, len); + if ((res = spa_json_begin(&iter, value, len, &val)) <= 0) + goto error; + + res = spa_json_to_pod_part(b, flags, info->type, info, &iter, val, len); + +error: + if (res < 0 && loc) + spa_json_get_error(&iter, value, loc); + return res; +} + +static inline int spa_json_to_pod(struct spa_pod_builder *b, uint32_t flags, + const struct spa_type_info *info, const char *value, int len) +{ + return spa_json_to_pod_checked(b, flags, info, value, len, NULL); } /** diff --git a/src/tools/pw-cli.c b/src/tools/pw-cli.c index 4b0e5a9d8..5ed7347fb 100644 --- a/src/tools/pw-cli.c +++ b/src/tools/pw-cli.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -1780,6 +1781,7 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char ** spa_auto(spa_pod_dynamic_builder) b = { 0 }; const struct spa_type_info *ti; struct spa_pod *pod; + struct spa_error_location loc; spa_pod_dynamic_builder_init(&b, buffer, sizeof(buffer), 4096); @@ -1804,8 +1806,13 @@ static bool do_set_param(struct data *data, const char *cmd, char *args, char ** *error = spa_aprintf("%s: unknown param type: %s", cmd, a[1]); return false; } - if ((res = spa_json_to_pod(&b.b, 0, ti, a[2], strlen(a[2]))) < 0) { - *error = spa_aprintf("%s: can't make pod: %s", cmd, spa_strerror(res)); + if ((res = spa_json_to_pod_checked(&b.b, 0, ti, a[2], strlen(a[2]), &loc)) < 0) { + if (loc.line != 0) { + spa_debug_file_error_location(stderr, &loc, + "syntax error in json '%s': %s", + a[2], loc.reason); + } + *error = spa_aprintf("%s: invalid pod: %s", cmd, loc.reason); return false; } if ((pod = spa_pod_builder_deref(&b.b, 0)) == NULL) {