From ea96513fd114bf812311e0316a75e7be193e6547 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 11 Nov 2023 18:52:39 +0900 Subject: [PATCH] op_store: deduplicate functions that map io::Error to OpStoreError io_to_read_error() also translates ErrorKind::NotFound. --- lib/src/simple_op_store.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/lib/src/simple_op_store.rs b/lib/src/simple_op_store.rs index 9a5d1225e..74147dfb2 100644 --- a/lib/src/simple_op_store.rs +++ b/lib/src/simple_op_store.rs @@ -97,7 +97,7 @@ impl OpStore for SimpleOpStore { fn read_view(&self, id: &ViewId) -> OpStoreResult { let path = self.view_path(id); - let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?; + let buf = fs::read(path).map_err(|err| io_to_read_error(err, id))?; let proto = crate::protos::op_store::View::decode(&*buf).map_err(|err| DecodeError { kind: "view", @@ -125,7 +125,7 @@ impl OpStore for SimpleOpStore { fn read_operation(&self, id: &OperationId) -> OpStoreResult { let path = self.operation_path(id); - let buf = fs::read(path).map_err(|err| not_found_to_store_error(err, id))?; + let buf = fs::read(path).map_err(|err| io_to_read_error(err, id))?; let proto = crate::protos::op_store::Operation::decode(&*buf).map_err(|err| DecodeError { @@ -153,14 +153,6 @@ impl OpStore for SimpleOpStore { } } -fn not_found_to_store_error(err: std::io::Error, id: &impl ObjectId) -> OpStoreError { - if err.kind() == ErrorKind::NotFound { - OpStoreError::NotFound - } else { - io_to_read_error(err, id) - } -} - fn io_to_read_error(err: std::io::Error, id: &impl ObjectId) -> OpStoreError { if err.kind() == ErrorKind::NotFound { OpStoreError::NotFound