db-snapshot: Add error handling to metadata snapshot creation #930

Open
baptiste wants to merge 2 commits from handle_snapshot_errors into main

View file

@ -482,7 +482,7 @@ impl AdminRpcHandler {
AdminRpc::MetaOperation(MetaOperation::Snapshot { all: false }), AdminRpc::MetaOperation(MetaOperation::Snapshot { all: false }),
PRIO_NORMAL, PRIO_NORMAL,
) )
.await .await?
})) }))
.await; .await;
@ -495,7 +495,14 @@ impl AdminRpcHandler {
ret.push(format!("{:?}\t{}", to, res_str)); ret.push(format!("{:?}\t{}", to, res_str));
} }
Ok(AdminRpc::Ok(format_table_to_string(ret))) if resps.iter().any(|resp| match resp {
Review

simplify: resps.iter().any(Result::is_err)

simplify: `resps.iter().any(Result::is_err)`
Review

I tried many different ways to simplify this code but I did not find anything satisfying. Thanks for the very nice solution :)

I tried many different ways to simplify this code but I did not find anything satisfying. Thanks for the very nice solution :)
Err(_) => true,
Ok(_) => false,
}) {
Err(Error::BadRequest(format_table_to_string(ret)).into())
Review

Error::Message is more appropriate here

`Error::Message` is more appropriate here
} else {
Ok(AdminRpc::Ok(format_table_to_string(ret)))
}
} }
MetaOperation::Snapshot { all: false } => { MetaOperation::Snapshot { all: false } => {
garage_model::snapshot::async_snapshot_metadata(&self.garage).await?; garage_model::snapshot::async_snapshot_metadata(&self.garage).await?;