Migrate errors to binder::IntoBinderResult
This removes some of the boilerplate and simplifies the code a little.
Most error handling was already centralized into a single helper, so
this isn't a big change.
Where I'm creating a new error, rather than reporting one from
elsewhere, I've used a straight String rather than anyhow!(); no need
for the extra functionality Anyhow provides.
Bug: 294348831
Test: composd_cmd test-compile
Test: Trigger binder error, see expected message
Change-Id: I68ebd5ce54131f84e7b0fd1af94fc1654702c5a5
diff --git a/compos/common/binder.rs b/compos/common/binder.rs
index d3550f7..aea0072 100644
--- a/compos/common/binder.rs
+++ b/compos/common/binder.rs
@@ -16,7 +16,7 @@
//! Helper for converting Error types to what Binder expects
-use binder::{Result as BinderResult, Status};
+use binder::{IntoBinderResult, Result as BinderResult};
use log::warn;
use std::fmt::Debug;
@@ -24,9 +24,9 @@
/// preserving the content as far as possible.
/// Also log the error if there is one.
pub fn to_binder_result<T, E: Debug>(result: Result<T, E>) -> BinderResult<T> {
- result.map_err(|e| {
+ result.or_service_specific_exception_with(-1, |e| {
let message = format!("{:?}", e);
- warn!("Returning binder error: {}", &message);
- Status::new_service_specific_error_str(-1, Some(message))
+ warn!("Returning binder error: {message}");
+ message
})
}