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
This commit is contained in:
Hyunjin Lee
2026-03-13 09:43:38 -05:00
committed by GitHub
parent ea9d456341
commit f426860c04
+15 -1
View File
@@ -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." return "Operation timed out. The page may still be loading or the element may not exist."
.to_string(); .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." return "Element not found. Verify the selector is correct and the element exists in the DOM."
.to_string(); .to_string();
} }
@@ -1237,4 +1237,18 @@ mod tests {
let msg = "Some custom error message"; let msg = "Some custom error message";
assert_eq!(to_ai_friendly_error(msg), msg); 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);
}
} }