Просмотр исходного кода

Now printing a warning message when a config has an unknown key (#3428)

* Now printing a warning message when unknown keys present
tofarr 1 год назад
Родитель
Сommit
b2221f135f
2 измененных файлов с 12 добавлено и 3 удалено
  1. 7 1
      opendevin/core/config.py
  2. 5 2
      opendevin/core/utils/singleton.py

+ 7 - 1
opendevin/core/config.py

@@ -514,7 +514,7 @@ def load_from_toml(cfg: AppConfig, toml_file: str = 'config.toml'):
                             )
                             agent_config = AgentConfig(**nested_value)
                             cfg.set_agent_config(agent_config, nested_key)
-                if key is not None and key.lower() == 'llm':
+                elif key is not None and key.lower() == 'llm':
                     logger.opendevin_logger.info(
                         'Attempt to load default LLM config from config toml'
                     )
@@ -530,11 +530,17 @@ def load_from_toml(cfg: AppConfig, toml_file: str = 'config.toml'):
                             )
                             llm_config = LLMConfig(**nested_value)
                             cfg.set_llm_config(llm_config, nested_key)
+                elif not key.startswith('sandbox') and key.lower() != 'core':
+                    logger.opendevin_logger.warning(
+                        f'Unknown key in {toml_file}: "{key}"'
+                    )
             except (TypeError, KeyError) as e:
                 logger.opendevin_logger.warning(
                     f'Cannot parse config from toml, toml values have not been applied.\n Error: {e}',
                     exc_info=False,
                 )
+        else:
+            logger.opendevin_logger.warning(f'Unknown key in {toml_file}: "{key}')
 
     try:
         # set sandbox config from the toml file

+ 5 - 2
opendevin/core/utils/singleton.py

@@ -1,5 +1,5 @@
 import dataclasses
-
+from opendevin.core import logger
 
 class Singleton(type):
     _instances: dict = {}
@@ -13,7 +13,10 @@ class Singleton(type):
             # useful for pre-defined groups of settings
             instance = cls._instances[cls]
             for key, value in kwargs.items():
-                setattr(instance, key, value)
+                if hasattr(instance, key):
+                    setattr(instance, key, value)
+                else:
+                    logger.opendevin_logger.warning(f'Unknown key for {cls.__name__}: "{key}"')
         return cls._instances[cls]
 
     @classmethod