From f426860c04243c54de3a3c2b7110cda38c9cda88 Mon Sep 17 00:00:00 2001 From: Hyunjin Lee Date: Fri, 13 Mar 2026 23:43:38 +0900 Subject: [PATCH] fix: narrow "not found" pattern in to_ai_friendly_error to avoid catching non-element errors (#759) * fix: narrow "not found" pattern in to_ai_friendly_error to avoid catching non-element errors Change `contains("not found")` to `contains("element not found")` so that connection/state errors like "Browser not found" pass through unchanged instead of being incorrectly mapped to "Element not found" message. * remove comment * fmt * test: use real project error message in non-element not found test --- cli/src/native/browser.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cli/src/native/browser.rs b/cli/src/native/browser.rs index 84172b7..f1df167 100644 --- a/cli/src/native/browser.rs +++ b/cli/src/native/browser.rs @@ -104,7 +104,7 @@ pub fn to_ai_friendly_error(error: &str) -> String { return "Operation timed out. The page may still be loading or the element may not exist." .to_string(); } - if lower.contains("not found") || lower.contains("no element") { + if lower.contains("element not found") || lower.contains("no element") { return "Element not found. Verify the selector is correct and the element exists in the DOM." .to_string(); } @@ -1237,4 +1237,18 @@ mod tests { let msg = "Some custom error message"; assert_eq!(to_ai_friendly_error(msg), msg); } + + /// Errors containing "not found" but NOT "element" should pass through unchanged. + #[test] + fn test_to_ai_friendly_error_ignores_non_element_not_found() { + let err = "Chrome not found. Install Chrome or use --executable-path."; + assert_eq!(to_ai_friendly_error(err), err); + } + + #[test] + fn test_to_ai_friendly_error_catches_no_element() { + let mapped = + "Element not found. Verify the selector is correct and the element exists in the DOM."; + assert_eq!(to_ai_friendly_error("No element found for css 'x'"), mapped); + } }