From 5868531e2293fd4816c2d02088e5197381c7b2a9 Mon Sep 17 00:00:00 2001 From: Crend King <975235+CrendKing@users.noreply.github.com> Date: Wed, 9 Aug 2023 19:11:43 -0700 Subject: [PATCH 1/2] Propagate error of unable to find midpoint upward instead of panicking --- src/browser/tab/element/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/browser/tab/element/mod.rs b/src/browser/tab/element/mod.rs index ed04cd1a..04eb11f4 100644 --- a/src/browser/tab/element/mod.rs +++ b/src/browser/tab/element/mod.rs @@ -526,11 +526,11 @@ 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); From 9497d0a4f5000af5bbc1ad23c81c23c694726523 Mon Sep 17 00:00:00 2001 From: Crend King <975235+CrendKing@users.noreply.github.com> Date: Sun, 27 Aug 2023 11:28:00 -0700 Subject: [PATCH 2/2] Fix build error --- src/browser/process.rs | 2 +- src/browser/tab/element/mod.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/browser/process.rs b/src/browser/process.rs index cf63d41e..db1a9f7c 100644 --- a/src/browser/process.rs +++ b/src/browser/process.rs @@ -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 { diff --git a/src/browser/tab/element/mod.rs b/src/browser/tab/element/mod.rs index 04eb11f4..43212b66 100644 --- a/src/browser/tab/element/mod.rs +++ b/src/browser/tab/element/mod.rs @@ -494,7 +494,7 @@ impl<'a> Element<'a> { Some(serde_json::from_value(attribute_value)?) } else { None - } + }, ) } @@ -527,10 +527,15 @@ impl<'a> Element<'a> { object_id: None, }) .and_then(|quad| { - quad.quads.first() + 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")) + .ok_or_else(|| { + anyhow::anyhow!( + "tried to get the midpoint of an element which is not visible" + ) + }) }) { return Ok(e);