segmented_changelog: expose inner error message in hash-to-location endpoint

Summary:
Previously it just passes "failed to compute the common descendant and distance
for X", the outmost layer (context) of the error to the client. Make it contain
more messages about the inner error and heads explicitly.

Reviewed By: StanislavGlebik

Differential Revision: D31071741

fbshipit-source-id: ec4f161491e14ae0e0c422f5e92a3849a5a29b56
This commit is contained in:
Jun Wu 2021-09-22 10:16:45 -07:00 committed by Facebook GitHub Bot
parent 3ef445c0a6
commit 4e0140653c

View File

@ -80,16 +80,21 @@ impl<'a> SegmentedChangelog for ReadOnlySegmentedChangelog<'a> {
.into_iter()
.filter_map(|(cs_id, dag_id)| {
// We do not return an entry when the asked commit is a descendant of client_head.
self.iddag
match self
.iddag
.to_first_ancestor_nth(dag_id, constraints.clone())
.with_context(|| {
format!(
"failed to compute the common descendant and distance for {}",
cs_id
)
})
.map(|opt| opt.map(|(v, dist)| (cs_id, Location::new(v, dist))))
.transpose()
{
// Preserve error message in server response by flatten the error.
Err(e) => Err(format_err!(
"failed to compute the common descendant and distance for {} with heads {:?}: {:?}",
cs_id,
&master_heads,
e
)),
Ok(v) => Ok(v),
}
.map(|opt| opt.map(|(v, dist)| (cs_id, Location::new(v, dist))))
.transpose()
})
.collect::<Result<HashMap<_, _>>>()?;
let common_cs_ids = {