ledflasher: Add graceful error handling

ledflasher relied on weaved/libweave for command parameter validation
which is no longer provided by libweave, so it needs to be less strict
about accepting commands with invalid parameters. Instead of just crashing
the application should just abort the command with corresponding error
message.

BUG: 25829264
Change-Id: Iae09b0d68006a1d5226d15d8b40552d42c7ab411
diff --git a/src/ledflasher/ledflasher.cpp b/src/ledflasher/ledflasher.cpp
index 4d43df2..5859647 100644
--- a/src/ledflasher/ledflasher.cpp
+++ b/src/ledflasher/ledflasher.cpp
@@ -109,22 +109,25 @@
     return;
 
   if (!led_service_) {
-    CHECK(command->Abort("system_error", "ledservice unavailable", nullptr));
+    command->Abort("system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   int index = command->GetParameter<int>("_led");
-  CHECK_GT(index, 0);
+  if(index < 1 || index > 4) {
+    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    return;
+  }
   bool on = command->GetParameter<bool>("_on");
   brillo::ErrorPtr error;
   if (!led_service_->SetLED(index - 1, on, &error)) {
-    CHECK(command->Abort(error->GetCode(), error->GetMessage(), nullptr));
+    command->Abort(error->GetCode(), error->GetMessage(), nullptr);
     return;
   }
   animation_.reset();
   status_ = "idle";
   UpdateDeviceState();
-  CHECK(command->Complete({}, nullptr));
+  command->Complete({}, nullptr);
 }
 
 void Daemon::OnToggle(const std::weak_ptr<weaved::Command>& cmd) {
@@ -133,24 +136,27 @@
     return;
 
   if (!led_service_) {
-    CHECK(command->Abort("system_error", "ledservice unavailable", nullptr));
+    command->Abort("system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   int index = command->GetParameter<int>("_led");
-  CHECK_GT(index, 0);
+  if(index < 1 || index > 4) {
+    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    return;
+  }
   index--;
   bool on = false;
   brillo::ErrorPtr error;
   if(!led_service_->GetLED(index, &on, &error) ||
      !led_service_->SetLED(index, !on, &error)) {
-    CHECK(command->Abort(error->GetCode(), error->GetMessage(), nullptr));
+    command->Abort(error->GetCode(), error->GetMessage(), nullptr);
     return;
   }
   animation_.reset();
   status_ = "idle";
   UpdateDeviceState();
-  CHECK(command->Complete({}, nullptr));
+  command->Complete({}, nullptr);
 }
 
 void Daemon::OnAnimate(const std::weak_ptr<weaved::Command>& cmd) {
@@ -159,11 +165,15 @@
     return;
 
   if (!led_service_) {
-    CHECK(command->Abort("system_error", "ledservice unavailable", nullptr));
+    command->Abort("system_error", "ledservice unavailable", nullptr);
     return;
   }
 
   double duration = command->GetParameter<double>("_duration");
+  if(duration <= 0.0) {
+    command->Abort("invalid_parameter", "Invalid parameter value", nullptr);
+    return;
+  }
   std::string type = command->GetParameter<std::string>("_type");
   animation_ = Animation::Create(led_service_, type,
                                  base::TimeDelta::FromSecondsD(duration));
@@ -174,7 +184,7 @@
     status_ = "idle";
   }
   UpdateDeviceState();
-  CHECK(command->Complete({}, nullptr));
+  command->Complete({}, nullptr);
 }
 
 void Daemon::UpdateDeviceState() {