Skip to content

Commit

Permalink
better logging of errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 11, 2023
1 parent 2d9278f commit 622f84f
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl Sodg {
loop {
let next = locator.pop_front();
if next.is_none() {
trace!("#find: end of locator, we are at ν{v}");
trace!("#find_with_closure: end of locator, we are at ν{v}");
break;
}
let k = next.unwrap().to_string();
Expand All @@ -329,21 +329,26 @@ impl Sodg {
if k.starts_with('ν') {
let num: String = k.chars().skip(1).collect::<Vec<_>>().into_iter().collect();
v = u32::from_str(num.as_str())?;
trace!("#find: jumping directly to ν{v}");
trace!("#find_with_closure: jumping directly to ν{v}");
continue;
}
if let Some(to) = self.kid(v, k.as_str()) {
trace!("#find: ν{v}.{k} -> ν{to}");
trace!("#find_with_closure: ν{v}.{k} -> ν{to}");
v = to;
continue;
};
let (head, tail) = Self::split_a(&k);
let redirect = cl(v, &head, &tail, self)?;
if let Ok(to) = self.find(v, redirect.as_str()) {
trace!("#find: ν{v}.{k} -> ν{to} (redirect to {redirect})");
v = to;
continue;
}
let redirect = cl(v, &head, &tail, self);
let failure = if let Ok(re) = redirect {
if let Ok(to) = self.find(v, re.as_str()) {
trace!("#find_with_closure: ν{v}.{k} -> ν{to} (redirect to {re})");
v = to;
continue;
}
format!("redirect to .{re} didn't help")
} else {
redirect.err().unwrap().to_string()
};
let others: Vec<String> = self
.vertices
.get(&v)
Expand All @@ -354,15 +359,15 @@ impl Sodg {
.map(|e| e.a.clone())
.collect();
return Err(anyhow!(
"Can't find .{} in ν{} among other {} attribute{}: {} (redirect to .{redirect} didn't help)",
"Can't find .{} in ν{} among other {} attribute{}: {} ({failure})",
k,
v,
others.len(),
if others.len() == 1 { "" } else { "s" },
others.join(", ")
));
}
trace!("#find: found ν{v1} by '{loc}'");
trace!("#find_with_closure: found ν{v1} by '{loc}'");
Ok(v)
}

Expand Down

0 comments on commit 622f84f

Please sign in to comment.