Cleanly error aos_starter when run before starterd
If fetching the status for an application before starterd had started
(and if doing so just for an individual application, rather than for
*all* applications), then aos_starter would segfault. Fail more
gracefully.
Change-Id: Ic4657d303403e116bc836dbf3803e43a533089b1
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/starter/starter_cmd.cc b/aos/starter/starter_cmd.cc
index ae65ff0..b3fb6c6 100644
--- a/aos/starter/starter_cmd.cc
+++ b/aos/starter/starter_cmd.cc
@@ -155,9 +155,20 @@
}
PrintKey();
for (const aos::Node *node : application_nodes) {
- auto status = aos::starter::GetStatus(application_name, config, node);
- PrintApplicationStatus(&status.message(), aos::monotonic_clock::now(),
- node);
+ auto optional_status =
+ aos::starter::GetStatus(application_name, config, node);
+ if (optional_status.has_value()) {
+ PrintApplicationStatus(&optional_status.value().message(),
+ aos::monotonic_clock::now(), node);
+ } else {
+ if (node != nullptr) {
+ LOG(ERROR) << "No status available yet for \"" << application_name
+ << "\" on node \"" << node->name()->string_view() << "\".";
+ } else {
+ LOG(ERROR) << "No status available yet for \"" << application_name
+ << "\".";
+ }
+ }
}
} else {
LOG(ERROR) << "The \"status\" command requires zero or one arguments.";