test_pattern_matching.pyโข2.35 kB
#!/usr/bin/env python3
"""Test script to verify error pattern matching improvements."""
def test_error_patterns():
"""Test the enhanced error pattern matching logic."""
# Test cases for different error message formats
test_errors = [
"index_not_found_exception: no such index [my_index]",
"IndexNotFoundError: no such index",
"The index [knowledge_base] does not exist",
"Index not found: knowledge_base",
"NOT_FOUND exception in elasticsearch",
"Connection refused",
"permission denied",
"mapping error occurred"
]
print("๐งช Testing Enhanced Error Pattern Matching")
print("=" * 50)
for i, error_msg in enumerate(test_errors, 1):
print(f"\n{i}. Testing error: '{error_msg}'")
error_str = error_msg.lower()
# Apply the enhanced pattern matching logic
if "connection" in error_str or "refused" in error_str:
result = "๐ Connection Error detected"
elif ("not_found" in error_str or "not found" in error_str or "does not exist" in error_str) or "index_not_found_exception" in error_str or "no such index" in error_str:
# Check if it's specifically an index not found error
if ("index" in error_str and ("not found" in error_str or "not_found" in error_str or "does not exist" in error_str)) or "index_not_found_exception" in error_str or "no such index" in error_str:
result = "๐ Index Not Found detected (with 4-step guidance)"
else:
result = "๐ Document Not Found detected"
elif "permission" in error_str or "forbidden" in error_str:
result = "๐ Permission Error detected"
elif "mapping" in error_str or "invalid" in error_str:
result = "๐ Mapping Error detected"
else:
result = "โ ๏ธ Unknown Error (fallback)"
print(f" โ {result}")
print(f"\nโ
Pattern matching test completed!")
print("๐ Summary: Enhanced patterns now detect:")
print(" โข index_not_found_exception")
print(" โข no such index")
print(" โข traditional not_found/not found patterns")
print(" โข proper index vs document error distinction")
if __name__ == "__main__":
test_error_patterns()