fix(config): add logging for config parse errors (#4955)
Co-authored-by: alihassan <239741857+alidevh@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ helper functions.
|
||||
"""
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
@@ -18,6 +19,7 @@ from framework.graph.edge import DEFAULT_MAX_TOKENS
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
HIVE_CONFIG_FILE = Path.home() / ".hive" / "configuration.json"
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_hive_config() -> dict[str, Any]:
|
||||
@@ -27,7 +29,12 @@ def get_hive_config() -> dict[str, Any]:
|
||||
try:
|
||||
with open(HIVE_CONFIG_FILE, encoding="utf-8-sig") as f:
|
||||
return json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
except (json.JSONDecodeError, OSError) as e:
|
||||
logger.warning(
|
||||
"Failed to load Hive config %s: %s",
|
||||
HIVE_CONFIG_FILE,
|
||||
e,
|
||||
)
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"""Tests for framework/config.py - Hive configuration loading."""
|
||||
|
||||
import logging
|
||||
|
||||
from framework.config import get_hive_config
|
||||
|
||||
|
||||
class TestGetHiveConfig:
|
||||
"""Test get_hive_config() logs warnings on parse errors."""
|
||||
|
||||
def test_logs_warning_on_malformed_json(self, tmp_path, monkeypatch, caplog):
|
||||
"""Test that malformed JSON logs warning and returns empty dict."""
|
||||
config_file = tmp_path / "configuration.json"
|
||||
config_file.write_text('{"broken": }')
|
||||
|
||||
monkeypatch.setattr("framework.config.HIVE_CONFIG_FILE", config_file)
|
||||
|
||||
with caplog.at_level(logging.WARNING):
|
||||
result = get_hive_config()
|
||||
|
||||
assert result == {}
|
||||
assert "Failed to load Hive config" in caplog.text
|
||||
assert str(config_file) in caplog.text
|
||||
Reference in New Issue
Block a user