Reuse error mapping logic for key operation metrics
Define SerializedError wire type for convenience and type safety. It
does not change the rules of how errors are downcasted to an i32.
Change operation outcome errors from Keymint ErrorCode to
SerializedError. This has an intended effect of binder errors being
reported to metrics as ResponseCode::SYSTEM_ERROR instead of
ErrorCode::UNKNOWN_ERROR.
Also update comments.
Bug: 298194325
Test: m
Change-Id: Ieff70245b776c38845c4f5142ab13d438ff79104
diff --git a/keystore2/src/operation.rs b/keystore2/src/operation.rs
index 2034a8a..eabc1ab 100644
--- a/keystore2/src/operation.rs
+++ b/keystore2/src/operation.rs
@@ -126,7 +126,10 @@
//! Either way, we have to revaluate the pruning scores.
use crate::enforcements::AuthInfo;
-use crate::error::{map_err_with, map_km_error, map_or_log_err, Error, ErrorCode, ResponseCode};
+use crate::error::{
+ error_to_serialized_error, map_err_with, map_km_error, map_or_log_err, Error, ErrorCode,
+ ResponseCode, SerializedError,
+};
use crate::ks_err;
use crate::metrics_store::log_key_operation_event_stats;
use crate::utils::watchdog as wd;
@@ -162,7 +165,7 @@
/// Operation is pruned.
Pruned,
/// Operation is failed with the error code.
- ErrorCode(ErrorCode),
+ ErrorCode(SerializedError),
}
/// Operation bundles all of the operation related resources and tracks the operation's
@@ -305,8 +308,7 @@
err: Result<T, Error>,
) -> Result<T, Error> {
match &err {
- Err(Error::Km(e)) => *locked_outcome = Outcome::ErrorCode(*e),
- Err(_) => *locked_outcome = Outcome::ErrorCode(ErrorCode::UNKNOWN_ERROR),
+ Err(e) => *locked_outcome = Outcome::ErrorCode(error_to_serialized_error(e)),
Ok(_) => (),
}
err