AOSCliUtils - channel filter error message

Rearranges channel checks in Initialize so user can be notified if a
channel exists in a config but fails to pass the channel_filter.

Example output:
$ ./aos_send /foo Msg '{}'
F20211210 09:43:42.628487 12011 aos_cli_utils.cc:103] matched channel does not pass the channel filter: "channel is sendable on node" [matched channel info]: { "name": "/foo", "type": "Msg", "frequency": 2, "max_size": 100000, "source_node": "pi0", "destination_nodes": [ { "name": "pi1", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi2", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi3", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi4", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi10", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi11", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi12", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi13", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 }, { "name": "pi14", "timestamp_logger": "LOCAL_AND_REMOTE_LOGGER", "timestamp_logger_nodes": [ "pi0" ], "priority": 4, "time_to_live": 0 } ], "logger": "LOCAL_AND_REMOTE_LOGGER", "logger_nodes": [ "pi1", "pi2", "pi3", "pi4", "pi10", "pi11", "pi12", "pi13", "pi14" ] }

Change-Id: Ie22ca616fd000d57fb19e4f564a28c1c5912a7d6
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/aos_cli_utils.cc b/aos/aos_cli_utils.cc
index 970797a..e0fe9ec 100644
--- a/aos/aos_cli_utils.cc
+++ b/aos/aos_cli_utils.cc
@@ -33,7 +33,7 @@
 bool CliUtilInfo::Initialize(
     int *argc, char ***argv,
     std::function<bool(const aos::Channel *)> channel_filter,
-    bool expect_args) {
+    std::string_view channel_filter_description, bool expect_args) {
   // Don't generate failure output if the config doesn't exist while attempting
   // to autocomplete.
   if (FLAGS__bash_autocomplete &&
@@ -87,12 +87,10 @@
     std::vector<const aos::Channel *> found_channels_now;
     bool found_exact = false;
     for (const aos::Channel *channel : *channels) {
-      if (!FLAGS_all && !channel_filter(channel)) {
-        continue;
-      }
       if (channel->name()->c_str() != channel_name) {
         continue;
       }
+
       if (channel->type()->string_view() == message_type) {
         if (!found_exact) {
           found_channels_now.clear();
@@ -103,6 +101,14 @@
       } else {
         continue;
       }
+
+      if (!FLAGS_all && !channel_filter(channel)) {
+        LOG(FATAL) << "matched channel does not pass the channel filter: \""
+                   << channel_filter_description
+                   << "\" [matched channel info]: "
+                   << configuration::CleanedChannelToString(channel);
+      }
+
       found_channels_now.push_back(channel);
     }