Skip to content

Commit a9f7ca3

Browse files
committed
Refactor ConfigManager error handling for configuration file loading
- Updated the ConfigManager to raise RuntimeError exceptions when the configuration file is not found or is invalid, improving error visibility and user guidance. - Removed fallback behavior that previously returned the current directory, ensuring users are explicitly informed about missing or invalid configuration files.
1 parent 89dafe6 commit a9f7ca3

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

config_manager.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ def _find_repo_root(self) -> Path:
7373
return current
7474
current = current.parent
7575

76-
# Fallback to cwd if not found
77-
logger.warning("Could not find config/config.yml, using current directory as repo root")
78-
return Path.cwd()
76+
# Raise error if not found
77+
raise RuntimeError(
78+
f"Could not find config/config.yml in directory tree starting from {Path.cwd()}. "
79+
"Please ensure you're running from within the Chronicle repository."
80+
)
7981

8082
def _detect_service_path(self) -> Optional[str]:
8183
"""Auto-detect service path from current working directory."""
@@ -100,15 +102,28 @@ def _detect_service_path(self) -> Optional[str]:
100102
def _load_config_yml(self) -> Dict[str, Any]:
101103
"""Load config.yml file."""
102104
if not self.config_yml_path.exists():
103-
logger.warning(f"config.yml not found at {self.config_yml_path}")
104-
return {}
105+
raise RuntimeError(
106+
f"Configuration file not found at {self.config_yml_path}. "
107+
"Please ensure config/config.yml exists in the repository root."
108+
)
105109

106110
try:
107111
with open(self.config_yml_path, 'r') as f:
108-
return yaml.safe_load(f) or {}
112+
config = yaml.safe_load(f)
113+
if config is None:
114+
raise RuntimeError(
115+
f"Configuration file {self.config_yml_path} is empty or invalid. "
116+
"Please ensure it contains valid YAML configuration."
117+
)
118+
return config
119+
except yaml.YAMLError as e:
120+
raise RuntimeError(
121+
f"Invalid YAML in configuration file {self.config_yml_path}: {e}"
122+
)
109123
except Exception as e:
110-
logger.error(f"Failed to load config.yml: {e}")
111-
return {}
124+
raise RuntimeError(
125+
f"Failed to load configuration file {self.config_yml_path}: {e}"
126+
)
112127

113128
def _save_config_yml(self, config: Dict[str, Any]):
114129
"""Save config.yml file with backup."""

0 commit comments

Comments
 (0)