Skip to content

Commit

Permalink
Merge pull request #410 from CrendKing/midpoint
Browse files Browse the repository at this point in the history
Propagate error of unable to find midpoint upward instead of panicking
  • Loading branch information
mdrokz committed Sep 8, 2023
2 parents 213c7e4 + 9497d0a commit e8f7b6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/browser/process.rs
Expand Up @@ -271,7 +271,7 @@ impl Process {
attempts += 1;
}

let mut child = process.0.borrow_mut();
let child = process.0.borrow_mut();
child.stderr = None;

Ok(Self {
Expand Down
17 changes: 11 additions & 6 deletions src/browser/tab/element/mod.rs
Expand Up @@ -494,7 +494,7 @@ impl<'a> Element<'a> {
Some(serde_json::from_value(attribute_value)?)
} else {
None
}
},
)
}

Expand Down Expand Up @@ -526,11 +526,16 @@ impl<'a> Element<'a> {
backend_node_id: Some(self.backend_node_id),
object_id: None,
})
.map(|quad| {
let raw_quad = quad.quads.first().expect("tried to get the midpoint of an element which is not visible");
let input_quad = ElementQuad::from_raw_points(raw_quad);

(input_quad.bottom_right + input_quad.top_left) / 2.0
.and_then(|quad| {
quad.quads
.first()
.map(|raw_quad| ElementQuad::from_raw_points(raw_quad))
.map(|input_quad| (input_quad.bottom_right + input_quad.top_left) / 2.0)
.ok_or_else(|| {
anyhow::anyhow!(
"tried to get the midpoint of an element which is not visible"
)
})
})
{
return Ok(e);
Expand Down

0 comments on commit e8f7b6b

Please sign in to comment.