summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-07-02 21:39:50 +0200
committerThomas Haller <thaller@redhat.com>2021-07-08 17:20:15 +0200
commitbb3c93bfd4d07fcbbd3703c9ba7899009665db71 (patch)
tree316031cb97b11d933885cfa4d2e98c8958360d5f
parent409c87af2c553a1c6ac63e869505f45c1406af45 (diff)
downloadNetworkManager-bb3c93bfd4d07fcbbd3703c9ba7899009665db71.tar.gz
cli: improve error message for device not found
$ nmcli connection add type ethernet con-name x autoconnect no ipv4.method disabled ipv6.method disabled $ nmcli connection up x ifname bogus Error: device 'bogus' not compatible with connection 'x'. Better would be: Error: device 'bogus' not found for connection 'x'.
-rw-r--r--src/nmcli/connections.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c
index db55c8f0ea..a6b5e58ea2 100644
--- a/src/nmcli/connections.c
+++ b/src/nmcli/connections.c
@@ -2488,8 +2488,9 @@ find_device_for_connection(NmCli * nmc,
}
} else {
/* Other connections */
- NMDevice * found_device = NULL;
- const GPtrArray *devices = nm_client_get_devices(nmc->client);
+ NMDevice * found_device = NULL;
+ const GPtrArray *devices = nm_client_get_devices(nmc->client);
+ gboolean found_device_with_name = FALSE;
for (i = 0; i < devices->len && !found_device; i++) {
NMDevice *dev = g_ptr_array_index(devices, i);
@@ -2499,6 +2500,7 @@ find_device_for_connection(NmCli * nmc,
if (!nm_streq0(dev_iface, iface))
continue;
+ found_device_with_name = TRUE;
if (!nm_device_connection_compatible(dev, connection, error)) {
g_prefix_error(error,
_("device '%s' not compatible with connection '%s': "),
@@ -2535,12 +2537,21 @@ find_device_for_connection(NmCli * nmc,
if (!found_device) {
if (iface) {
- g_set_error(error,
- NMCLI_ERROR,
- 0,
- _("device '%s' not compatible with connection '%s'"),
- iface,
- nm_setting_connection_get_id(s_con));
+ if (found_device_with_name) {
+ g_set_error(error,
+ NMCLI_ERROR,
+ 0,
+ _("device '%s' not compatible with connection '%s'"),
+ iface,
+ nm_setting_connection_get_id(s_con));
+ } else {
+ g_set_error(error,
+ NMCLI_ERROR,
+ 0,
+ _("device '%s' not found for connection '%s'"),
+ iface,
+ nm_setting_connection_get_id(s_con));
+ }
} else {
g_set_error(error,
NMCLI_ERROR,