summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Vakulenko <avakulenko@google.com>2015-11-24 17:31:17 -0800
committerAlex Vakulenko <avakulenko@google.com>2015-11-24 17:31:17 -0800
commit6ec1e3f77835251128ccf4f893d5d18838b32db5 (patch)
treeb8e0cf2831d94fd7d1b550823a222dcc097d805f
parent47be954a7b4c9891d9f565560cdaf1eda2d7d80b (diff)
downloadexample-ledflasher-6ec1e3f77835251128ccf4f893d5d18838b32db5.tar.gz
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
-rw-r--r--src/ledflasher/ledflasher.cpp30
1 files changed, 20 insertions, 10 deletions
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 @@ void Daemon::OnSet(const std::weak_ptr<weaved::Command>& cmd) {
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 @@ void Daemon::OnToggle(const std::weak_ptr<weaved::Command>& cmd) {
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 @@ void Daemon::OnAnimate(const std::weak_ptr<weaved::Command>& cmd) {
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 @@ void Daemon::OnAnimate(const std::weak_ptr<weaved::Command>& cmd) {
status_ = "idle";
}
UpdateDeviceState();
- CHECK(command->Complete({}, nullptr));
+ command->Complete({}, nullptr);
}
void Daemon::UpdateDeviceState() {