ciyidogan commited on
Commit
0ec6123
·
verified ·
1 Parent(s): a62c0f4

Update config_provider.py

Browse files
Files changed (1) hide show
  1. config_provider.py +27 -2
config_provider.py CHANGED
@@ -411,8 +411,18 @@ class ConfigProvider:
411
  if not cls._CONFIG_PATH.exists():
412
  raise FileNotFoundError(f"Config file not found: {cls._CONFIG_PATH}")
413
 
414
- with open(cls._CONFIG_PATH, 'r', encoding='utf-8') as f:
415
- config_data = commentjson.load(f)
 
 
 
 
 
 
 
 
 
 
416
 
417
  # Ensure required fields exist in config data
418
  if 'config' not in config_data:
@@ -454,6 +464,21 @@ class ConfigProvider:
454
  except Exception as e:
455
  log(f"❌ Error loading config: {e}")
456
  raise
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
 
458
  @classmethod
459
  def _migrate_old_config(cls, config_data: dict):
 
411
  if not cls._CONFIG_PATH.exists():
412
  raise FileNotFoundError(f"Config file not found: {cls._CONFIG_PATH}")
413
 
414
+ # Read raw content
415
+ raw_content = cls._CONFIG_PATH.read_text(encoding='utf-8')
416
+
417
+ # Try commentjson first, fallback to manual cleaning
418
+ try:
419
+ with open(cls._CONFIG_PATH, 'r', encoding='utf-8') as f:
420
+ config_data = commentjson.load(f)
421
+ except Exception as e:
422
+ log(f"⚠️ commentjson failed ({str(e)[:100]}...), trying manual JSON cleaning...")
423
+ # Manual cleaning - remove comments and trailing commas
424
+ cleaned = cls._strip_jsonc(raw_content)
425
+ config_data = json.loads(cleaned)
426
 
427
  # Ensure required fields exist in config data
428
  if 'config' not in config_data:
 
464
  except Exception as e:
465
  log(f"❌ Error loading config: {e}")
466
  raise
467
+
468
+ @staticmethod
469
+ def _strip_jsonc(text: str) -> str:
470
+ """Remove comments and trailing commas from JSONC"""
471
+ # Remove single-line comments
472
+ text = re.sub(r'//.*$', '', text, flags=re.MULTILINE)
473
+
474
+ # Remove multi-line comments
475
+ text = re.sub(r'/\*.*?\*/', '', text, flags=re.DOTALL)
476
+
477
+ # Remove trailing commas before } or ]
478
+ # This is the critical fix for line 107 error
479
+ text = re.sub(r',\s*([}\]])', r'\1', text)
480
+
481
+ return text
482
 
483
  @classmethod
484
  def _migrate_old_config(cls, config_data: dict):