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);
     }
 
diff --git a/aos/aos_cli_utils.h b/aos/aos_cli_utils.h
index 962e0a0..a2d8c62 100644
--- a/aos/aos_cli_utils.h
+++ b/aos/aos_cli_utils.h
@@ -14,6 +14,7 @@
   // event_loop will be filled out before channel_filter is called.
   bool Initialize(int *argc, char ***argv,
                   std::function<bool(const aos::Channel *)> channel_filter,
+                  std::string_view channel_filter_description,
                   bool expect_args);
 
   std::optional<aos::FlatbufferDetachedBuffer<aos::Configuration>> config;
diff --git a/aos/aos_dump.cc b/aos/aos_dump.cc
index a13ad9a..2fe4955 100644
--- a/aos/aos_dump.cc
+++ b/aos/aos_dump.cc
@@ -83,7 +83,7 @@
             return aos::configuration::ChannelIsReadableOnNode(
                 channel, cli_info.event_loop->node());
           },
-          true)) {
+          "channel is readeable on node", true)) {
     return 0;
   }
 
diff --git a/aos/aos_send.cc b/aos/aos_send.cc
index 515da71..b8cc9eb 100644
--- a/aos/aos_send.cc
+++ b/aos/aos_send.cc
@@ -29,7 +29,7 @@
             return aos::configuration::ChannelIsSendableOnNode(
                 channel, cli_info.event_loop->node());
           },
-          false)) {
+          "channel is sendable on node", false)) {
     return 0;
   }
   if (cli_info.found_channels.size() > 1) {