fix(config): log configuration loading errors instead of silently ignoring

Replaces bare exception handler in load_settings() with logging.warning()
to help users debug configuration file issues (syntax errors, permissions).
Maintains backward compatibility - errors do not break initialization.

Solution-ID: SOL-1735385400001
Issue-ID: ISS-1766921318981-1
Task-ID: T1
This commit is contained in:
catlog22
2025-12-28 21:06:23 +08:00
parent 58caccb250
commit 93dcdd2293
2 changed files with 115 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
from __future__ import annotations
import json
import logging
import os
from dataclasses import dataclass, field
from functools import cached_property
@@ -18,6 +19,8 @@ WORKSPACE_DIR_NAME = ".codexlens"
# Settings file name
SETTINGS_FILE_NAME = "settings.json"
log = logging.getLogger(__name__)
def _default_global_dir() -> Path:
"""Get global CodexLens data directory."""
@@ -200,7 +203,15 @@ class Config:
# Load embedding settings
embedding = settings.get("embedding", {})
if "backend" in embedding:
self.embedding_backend = embedding["backend"]
backend = embedding["backend"]
if backend in {"fastembed", "litellm"}:
self.embedding_backend = backend
else:
log.warning(
"Invalid embedding backend in %s: %r (expected 'fastembed' or 'litellm')",
self.settings_path,
backend,
)
if "model" in embedding:
self.embedding_model = embedding["model"]
if "use_gpu" in embedding:
@@ -224,8 +235,13 @@ class Config:
self.llm_timeout_ms = llm["timeout_ms"]
if "batch_size" in llm:
self.llm_batch_size = llm["batch_size"]
except Exception:
pass # Silently ignore errors
except Exception as exc:
log.warning(
"Failed to load settings from %s (%s): %s",
self.settings_path,
type(exc).__name__,
exc,
)
@classmethod
def load(cls) -> "Config":