From bb3c93bfd4d07fcbbd3703c9ba7899009665db71 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 2 Jul 2021 21:39:50 +0200 Subject: [PATCH] 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'. --- src/nmcli/connections.c | 27 +++++++++++++++++++-------- 1 file 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,