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: add UnicodeDecodeError to _load_legacy_config exception handler (#2679)

LearningCircuitad32af946bfe
diff --git a/src/local_deep_research/web/server_config.py b/src/local_deep_research/web/server_config.py
index 51f238f7fe..56fde33fc7 100644
--- a/src/local_deep_research/web/server_config.py
+++ b/src/local_deep_research/web/server_config.py
@@ -109,7 +109,7 @@ def _load_legacy_config() -> Dict[str, Any]:
try:
data = json.loads(config_path.read_text(encoding="utf-8-sig"))
- except (json.JSONDecodeError, OSError) as exc:
+ except (json.JSONDecodeError, OSError, UnicodeDecodeError) as exc:
logger.warning(
f"Could not read legacy server_config.json at {config_path}: "
f"{exc}. Ignoring file."
diff --git a/tests/web/test_server_config.py b/tests/web/test_server_config.py
index f53e4c2635..8a36d8c4ab 100644
--- a/tests/web/test_server_config.py
+++ b/tests/web/test_server_config.py
@@ -408,6 +408,22 @@ class TestLegacyMigration:
warning_calls = [str(c) for c in mock_logger.warning.call_args_list]
assert any("Could not read" in call for call in warning_calls)
+ @pytest.mark.usefixtures("_passthrough_typed_setting")
+ def test_corrupt_encoding_falls_back_to_defaults(self, _mock_data_dir):
+ """Invalid UTF-8 bytes should log a warning and return defaults."""
+ (_mock_data_dir / "server_config.json").write_bytes(
+ b"\x80\xfe\xff invalid utf-8"
+ )
+ with patch(
+ "local_deep_research.web.server_config.logger"
+ ) as mock_logger:
+ result = load_server_config()
+
+ assert result["host"] == "0.0.0.0"
+ assert result["allow_registrations"] is True
+ warning_calls = [str(c) for c in mock_logger.warning.call_args_list]
+ assert any("Could not read" in call for call in warning_calls)
+
@pytest.mark.usefixtures("_passthrough_typed_setting")
def test_non_dict_json_falls_back_to_defaults(self, _mock_data_dir):
"""Non-dict JSON (e.g. array) should log a warning and return defaults."""
@@ -625,3 +641,9 @@ class TestHasLegacyCustomizations:
cfg = tmp_path / "server_config.json"
cfg.write_text("not valid json", encoding="utf-8")
assert has_legacy_customizations(cfg) is False
+
+ def test_returns_false_on_corrupt_encoding(self, tmp_path):
+ """Invalid UTF-8 bytes should return False, not raise."""
+ cfg = tmp_path / "server_config.json"
+ cfg.write_bytes(b"\x80\xfe\xff invalid utf-8")
+ assert has_legacy_customizations(cfg) is False