Map a `PersistenceError` to an appropriate gRPC `Status`. CAS conflicts (optimistic concurrency failures) are mapped to `ABORTED` to signal that the client should retry with fresh data. Other persistence errors are mapped to `INTERNAL`.
(
err: crate::persistence::PersistenceError,
operation: &str,
)
| 78 | /// to signal that the client should retry with fresh data. Other persistence |
| 79 | /// errors are mapped to `INTERNAL`. |
| 80 | pub fn persistence_error_to_status( |
| 81 | err: crate::persistence::PersistenceError, |
| 82 | operation: &str, |
| 83 | ) -> Status { |
| 84 | use crate::persistence::PersistenceError; |
| 85 | |
| 86 | match err { |
| 87 | PersistenceError::Conflict { |
| 88 | current_resource_version, |
| 89 | } => Status::aborted(format!( |
| 90 | "{} failed due to concurrent modification (current resource_version: {})", |
| 91 | operation, |
| 92 | current_resource_version.map_or_else(|| "unknown".to_string(), |v| v.to_string()) |
| 93 | )), |
| 94 | other => Status::internal(format!("{operation} failed: {other}")), |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // --------------------------------------------------------------------------- |
| 99 | // Field-level size limits (shared across submodules) |
no outgoing calls
no test coverage detected