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(errors): preserve tailored error messages in error report generator (#4087)

LearningCircuitddc9ce14a5e6
diff --git a/src/local_deep_research/error_handling/report_generator.py b/src/local_deep_research/error_handling/report_generator.py
index 39afe5e95b..b16912abab 100644
--- a/src/local_deep_research/error_handling/report_generator.py
+++ b/src/local_deep_research/error_handling/report_generator.py
@@ -2,6 +2,7 @@
ErrorReportGenerator - Create user-friendly error reports
"""
+import re
from typing import Any, Dict, Optional
from loguru import logger
@@ -294,6 +295,24 @@ We're here to help you get this working:
Returns:
str: User-friendly error message, or original if no replacement found
"""
+ # Messages carrying a SPECIFIC "(Error type: <code>)" token have already
+ # been classified and rewritten into user-friendly text by upstream code
+ # (openai_compat_errors, the Ollama/status-code branches in
+ # research_service). Return those unchanged -- the regex patterns below
+ # are meant for raw, unrewritten exceptions only, and would otherwise
+ # clobber the tailored upstream message (e.g. the openai_connection_refused
+ # message getting overwritten by the generic "Connection refused" hint).
+ #
+ # "(Error type: unknown)", however, is attached to a RAW exception string
+ # that upstream could NOT classify (research_service appends the token to
+ # str(exc) verbatim). Let those fall through to the replacement table
+ # below -- it acts as a second-chance classifier and can only add help to
+ # an otherwise-cryptic message, never clobber friendly text.
+ if (
+ re.search(r"\(Error type: \w+\)", error_message)
+ and "(Error type: unknown)" not in error_message
+ ):
+ return error_message
# Dictionary of technical errors to user-friendly messages
error_replacements = {
"max_workers must be greater than 0": (
@@ -423,8 +442,6 @@ We're here to help you get this working:
# Check each pattern and replace if found
for pattern, replacement in error_replacements.items():
- import re
-
if re.search(pattern, error_message, re.IGNORECASE):
return f"{replacement}\n\nTechnical error: {error_message}"
diff --git a/tests/error_handling/test_report_generator_behavior.py b/tests/error_handling/test_report_generator_behavior.py
index 5c5e323b6f..b13fe586ed 100644
--- a/tests/error_handling/test_report_generator_behavior.py
+++ b/tests/error_handling/test_report_generator_behavior.py
@@ -218,6 +218,89 @@ class TestMakeErrorUserFriendly:
assert result == msg
+class TestErrorTypeTokenShortCircuit:
+ """Tests for the ``(Error type: <code>)`` short-circuit in
+ ``_make_error_user_friendly()`` (PR #4087).
+
+ Upstream code (``openai_compat_errors``, the status-code/Ollama branches in
+ ``research_service``) emits already-friendly messages carrying a
+ ``(Error type: <code>)`` token. The replacement table must NOT clobber those
+ -- but the ``unknown`` token is attached to a RAW exception string upstream
+ could not classify, so it must still fall through to the table.
+ """
+
+ def test_specific_token_message_returned_verbatim(self):
+ # The actual #4087 bug: friendly_openai_compatible_error() builds a
+ # message that names the provider/URL/model AND happens to contain the
+ # substrings "Connection refused" / the Docker hint, which the generic
+ # replacement patterns matched and overwrote. With the short-circuit it
+ # must be returned untouched.
+ from local_deep_research.error_handling.report_generator import (
+ ErrorReportGenerator,
+ )
+
+ gen = ErrorReportGenerator()
+ msg = (
+ "Cannot reach LM Studio at http://localhost:1234. Check that the "
+ "server is running and the URL is correct. (from inside Docker, "
+ "localhost is the container itself -- use host.docker.internal, the "
+ "host IP, or run with --network=host to share the host network "
+ "namespace) (Error type: openai_connection_refused) | Details: "
+ "Connection refused [Errno 111]"
+ )
+ result = gen._make_error_user_friendly(msg)
+
+ # Returned verbatim -- the tailored message survives.
+ assert result == msg
+ # And specifically NOT replaced by either generic hint.
+ assert "Cannot connect to the LLM service" not in result
+ assert "Docker networking issue" not in result
+
+ def test_non_token_message_still_replaced(self):
+ # Over-fire guard: a raw exception with NO token must still be
+ # classified by the replacement table.
+ from local_deep_research.error_handling.report_generator import (
+ ErrorReportGenerator,
+ )
+
+ gen = ErrorReportGenerator()
+ result = gen._make_error_user_friendly("Connection refused [Errno 111]")
+
+ assert "Cannot connect to the LLM service" in result
+ assert "Technical error:" in result
+
+ def test_unknown_token_falls_through_to_replacement_table(self):
+ # The #4087 follow-up fix: "(Error type: unknown)" is appended by
+ # research_service to a RAW str(exc) it could not classify (e.g. the
+ # LLM generated no questions -> ThreadPoolExecutor(max_workers=0)).
+ # It must still get the friendly replacement, with the original message
+ # (token included) preserved in the technical-error suffix.
+ from local_deep_research.error_handling.report_generator import (
+ ErrorReportGenerator,
+ )
+
+ gen = ErrorReportGenerator()
+ msg = "max_workers must be greater than 0 (Error type: unknown)"
+ result = gen._make_error_user_friendly(msg)
+
+ assert "LLM failed to generate search questions" in result
+ assert "Technical error:" in result
+ assert "(Error type: unknown)" in result
+
+ def test_unknown_token_with_no_match_returns_original(self):
+ # Falling through is safe when nothing matches: an unclassifiable
+ # "unknown" message is returned as-is, exactly as before.
+ from local_deep_research.error_handling.report_generator import (
+ ErrorReportGenerator,
+ )
+
+ gen = ErrorReportGenerator()
+ msg = "Totally novel failure xyz123 (Error type: unknown)"
+ result = gen._make_error_user_friendly(msg)
+
+ assert result == msg
+
+
class TestFormatPartialResults:
"""Tests for ErrorReportGenerator._format_partial_results() method."""