From 492bdea3f25c287159cbb61b78951515cc06c4b3 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 8 May 2017 10:42:05 +0200 Subject: [PATCH] clients: print expected route syntax on parsing failure Now that routes can include optional attributes, print the expected syntax in case of parsing failure. $ nmcli connection modify dummy ipv4.routes a Error: failed to modify ipv4.routes: invalid route: Invalid IPv4 address 'a'. The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] ...]'. (cherry picked from commit 00df57a0667018b678ce8d03c6226a4e239eafaf) --- clients/cli/common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/clients/cli/common.c b/clients/cli/common.c index aa2189d113..4d89c3f86b 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -423,6 +423,7 @@ nmc_parse_and_build_route (int family, gs_free char *dest = NULL; gs_unref_hashtable GHashTable *attrs = NULL; GHashTable *tmp_attrs; + const char *syntax = _("The valid syntax is: 'ip[/prefix] [next-hop] [metric] [attribute=val]... [,ip[/prefix] ...]'"); g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE); g_return_val_if_fail (str, FALSE); @@ -432,8 +433,8 @@ nmc_parse_and_build_route (int family, routev = nmc_strsplit_set (g_strstrip (value), " \t", 0); len = g_strv_length (routev); if (len < 1) { - g_set_error (error, 1, 0, _("'%s' is not valid (the format is: ip[/prefix] [next-hop] [metric] [attr=val] [attr=val])"), - str); + g_set_error (error, 1, 0, "%s", syntax); + g_prefix_error (error, "'%s' is not valid. ", str); goto finish; } @@ -492,15 +493,15 @@ nmc_parse_and_build_route (int family, } g_hash_table_unref (tmp_attrs); } else { - g_set_error (error, 1, 0, _("unrecognized option '%s'"), routev[i]); + g_set_error (error, 1, 0, "%s", syntax); goto finish; } } route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local); if (!route) { - g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT, - _("invalid route: %s"), local->message); + g_set_error (error, 1, 0, "%s", syntax); + g_prefix_error (error, _("invalid route: %s. "), local->message); g_clear_error (&local); goto finish; }