Enhance .env loading mechanism and EdgeDTO creation with error handling
Deploy mindnet to llm-node / deploy (push) Successful in 4s

- Updated the .env loading process to first check for an explicit path, improving reliability in different working directories.
- Added logging for successful .env loading and fallback mechanisms.
- Enhanced EdgeDTO creation with robust error handling, including fallbacks for unsupported provenance values and logging of errors for better traceability.
This commit is contained in:
Lars committed 2026-01-12 15:27:23 +01:00
1 parent df5f9b3fe4
commit 6d268d9dfb
7 files changed
+620 -12

No files matched your search

+28 -1
View File
@@ -15,7 +15,34 @@ from dotenv import load_dotenv
# WP-20: Lade Umgebungsvariablen aus der .env Datei
# override=True garantiert, dass Änderungen in der .env immer Vorrang haben.
load_dotenv(override=True)
# WP-24c v4.5.10: Expliziter Pfad für .env-Datei, um Probleme mit Arbeitsverzeichnis zu vermeiden
# Suche .env im Projekt-Root (3 Ebenen über app/config.py: app/config.py -> app/ -> root/)
_project_root = Path(__file__).parent.parent.parent
_env_file = _project_root / ".env"
_env_loaded = False
# Versuche zuerst expliziten Pfad
if _env_file.exists():
_env_loaded = load_dotenv(_env_file, override=True)
if _env_loaded:
# Optional: Logging (nur wenn logging bereits initialisiert ist)
try:
import logging
_logger = logging.getLogger(__name__)
_logger.debug(f"✅ .env geladen von: {_env_file}")
except:
pass # Logging noch nicht initialisiert
# Fallback: Automatische Suche (für Dev/Test oder wenn .env an anderer Stelle liegt)
if not _env_loaded:
_env_loaded = load_dotenv(override=True)
if _env_loaded:
try:
import logging
_logger = logging.getLogger(__name__)
_logger.debug(f"✅ .env geladen via automatische Suche (cwd: {Path.cwd()})")
except:
pass
class Settings:
# --- Qdrant Datenbank ---
+36 -11
View File
@@ -216,17 +216,42 @@ def _build_explanation(
direction = "in" if tgt == target_note_id else "out"
edge_obj = EdgeDTO(
id=f"{src}->{tgt}:{kind}",
kind=kind,
source=src,
target=tgt,
weight=conf,
direction=direction,
provenance=prov,
confidence=conf
)
edges_dto.append(edge_obj)
# WP-24c v4.5.10: Robuste EdgeDTO-Erstellung mit Fehlerbehandlung
# Falls Provenance-Wert nicht unterstützt wird, verwende Fallback
try:
edge_obj = EdgeDTO(
id=f"{src}->{tgt}:{kind}",
kind=kind,
source=src,
target=tgt,
weight=conf,
direction=direction,
provenance=prov,
confidence=conf
)
edges_dto.append(edge_obj)
except Exception as e:
# WP-24c v4.5.10: Fallback bei Validierungsfehler (z.B. alte EdgeDTO-Version im Cache)
logger.warning(
f"⚠️ [EDGE-DTO] Provenance '{prov}' nicht unterstützt für Edge {src}->{tgt} ({kind}). "
f"Fehler: {e}. Verwende Fallback 'explicit'."
)
# Fallback: Verwende 'explicit' als sicheren Default
try:
edge_obj = EdgeDTO(
id=f"{src}->{tgt}:{kind}",
kind=kind,
source=src,
target=tgt,
weight=conf,
direction=direction,
provenance="explicit", # Fallback
confidence=conf
)
edges_dto.append(edge_obj)
except Exception as e2:
logger.error(f"❌ [EDGE-DTO] Auch Fallback fehlgeschlagen: {e2}. Überspringe Edge.")
# Überspringe diese Kante - besser als kompletter Fehler
# Die 3 wichtigsten Kanten als Begründung formulieren
top_edges = sorted(edges_dto, key=lambda e: e.confidence, reverse=True)