feat(settings): add validation for settings.json to ensure required configuration is present

fix(usage_stats): handle initialization errors for usage statistics when no valid paths are configured, fixes #375
This commit is contained in:
Will Miao
2025-09-06 17:39:51 +08:00
parent c23ab04d90
commit 74507cef05
3 changed files with 64 additions and 3 deletions

View File

@@ -67,8 +67,9 @@ class UsageStats:
def _get_stats_file_path(self) -> str:
"""Get the path to the stats JSON file"""
if not config.loras_roots or len(config.loras_roots) == 0:
# Fallback to temporary directory if no lora roots
return os.path.join(config.temp_directory, self.STATS_FILENAME)
# If no lora roots are available, we can't save stats
# This will be handled by the caller
raise RuntimeError("No LoRA root directories configured. Cannot initialize usage statistics.")
# Use the first lora root
return os.path.join(config.loras_roots[0], self.STATS_FILENAME)