Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: replace bare except clauses in api, web routes, and classifier (#2027)

LearningCircuit71328acb31e5
diff --git a/src/local_deep_research/api/client.py b/src/local_deep_research/api/client.py
index 279f2e606a..9f06ba41ee 100644
--- a/src/local_deep_research/api/client.py
+++ b/src/local_deep_research/api/client.py
@@ -230,7 +230,7 @@ class LDRClient:
error_msg = error_data[0].get("message", "Unknown error")
else:
error_msg = str(error_data)
- except:
+ except Exception:
error_msg = response.text[:200]
raise RuntimeError(f"Failed to start research: {error_msg}")
diff --git a/src/local_deep_research/domain_classifier/classifier.py b/src/local_deep_research/domain_classifier/classifier.py
index 05211147e3..49183b0fb7 100644
--- a/src/local_deep_research/domain_classifier/classifier.py
+++ b/src/local_deep_research/domain_classifier/classifier.py
@@ -310,7 +310,7 @@ JSON Response:"""
domain = domain[4:]
if domain:
domains.add(domain)
- except:
+ except Exception:
continue
results["total"] = len(domains)
diff --git a/tests/api/test_client_extended.py b/tests/api/test_client_extended.py
index e43c2a5e21..2c401bc655 100644
--- a/tests/api/test_client_extended.py
+++ b/tests/api/test_client_extended.py
@@ -683,3 +683,53 @@ class TestHistoryHandling:
result = client.get_history()
assert result == [{"id": 3}]
+
+
+class TestErrorResponseParsing:
+ """Tests for error response JSON parsing (PR #2027).
+
+ PR #2027 changed bare `except:` to `except Exception:` when
+ parsing error JSON from failed API responses.
+ """
+
+ def test_valid_json_error_parsed(self):
+ """Valid JSON error response is parsed."""
+ import json
+
+ error_body = json.dumps([{"message": "Bad request"}])
+ try:
+ data = json.loads(error_body)
+ if isinstance(data, list) and len(data) > 0:
+ msg = data[0].get("message", "Unknown error")
+ else:
+ msg = str(data)
+ except Exception:
+ msg = error_body[:200]
+
+ assert msg == "Bad request"
+
+ def test_invalid_json_falls_back_to_text(self):
+ """Invalid JSON falls back to raw text (caught by except Exception)."""
+ error_body = "Not JSON at all"
+ try:
+ import json
+
+ data = json.loads(error_body)
+ msg = str(data)
+ except Exception:
+ msg = error_body[:200]
+
+ assert msg == "Not JSON at all"
+
+ def test_empty_response_falls_back(self):
+ """Empty response body falls back to text."""
+ error_body = ""
+ try:
+ import json
+
+ data = json.loads(error_body)
+ msg = str(data)
+ except Exception:
+ msg = error_body[:200]
+
+ assert msg == ""
diff --git a/tests/domain_classifier/test_domain_classifier.py b/tests/domain_classifier/test_domain_classifier.py
index 4cf9b03167..2b35668479 100644
--- a/tests/domain_classifier/test_domain_classifier.py
+++ b/tests/domain_classifier/test_domain_classifier.py
@@ -326,3 +326,43 @@ class TestCategoryValidation:
assert len(unique_subcats) == len(subcategories), (
f"Duplicate subcategories in {category}"
)
+
+
+class TestUrlparseExceptionInClassifyAll:
+ """Tests for urlparse exception handling in classify_all_domains (PR #2027).
+
+ PR #2027 changed bare `except:` to `except Exception:` when
+ parsing URLs to extract domains.
+ """
+
+ def test_valid_url_extracts_domain(self):
+ """Valid URL extracts domain correctly."""
+ from urllib.parse import urlparse
+
+ url = "https://www.example.com/path"
+ parsed = urlparse(url)
+ domain = parsed.netloc.lower()
+ if domain.startswith("www."):
+ domain = domain[4:]
+
+ assert domain == "example.com"
+
+ def test_url_without_scheme_no_netloc(self):
+ """URL without scheme has no netloc."""
+ from urllib.parse import urlparse
+
+ url = "just-some-text"
+ parsed = urlparse(url)
+ domain = parsed.netloc.lower()
+
+ assert domain == ""
+
+ def test_empty_url_handled(self):
+ """Empty URL string produces empty domain."""
+ from urllib.parse import urlparse
+
+ url = ""
+ parsed = urlparse(url)
+ domain = parsed.netloc.lower()
+
+ assert domain == ""