op_store: embed details in operation/view not found error

This is basically a copy of BackendError::ObjectNotFound. The failed id may
be either view or operation id.
This commit is contained in:
Yuya Nishihara 2023-11-11 18:59:06 +09:00
parent ea96513fd1
commit 6125fb160e
3 changed files with 12 additions and 4 deletions

View file

@ -1958,7 +1958,7 @@ fn resolve_single_op_from_store(
Ok(operation) => {
return Ok(Operation::new(op_store.clone(), op_id, operation));
}
Err(OpStoreError::NotFound) => {
Err(OpStoreError::ObjectNotFound { .. }) => {
// Fall through
}
Err(err) => {

View file

@ -384,8 +384,12 @@ content_hash! {
#[derive(Debug, Error)]
pub enum OpStoreError {
#[error("Operation not found")]
NotFound,
#[error("Object {hash} of type {object_type} not found: {source}")]
ObjectNotFound {
object_type: String,
hash: String,
source: Box<dyn std::error::Error + Send + Sync>,
},
#[error("Error when reading object {hash} of type {object_type}: {source}")]
ReadObject {
object_type: String,

View file

@ -155,7 +155,11 @@ impl OpStore for SimpleOpStore {
fn io_to_read_error(err: std::io::Error, id: &impl ObjectId) -> OpStoreError {
if err.kind() == ErrorKind::NotFound {
OpStoreError::NotFound
OpStoreError::ObjectNotFound {
object_type: id.object_type(),
hash: id.hex(),
source: Box::new(err),
}
} else {
OpStoreError::ReadObject {
object_type: id.object_type(),