From d2d07ed92d9eb8bc245023fcde8c19f49e437c77 Mon Sep 17 00:00:00 2001 From: kingbri Date: Mon, 16 Sep 2024 18:15:50 -0400 Subject: [PATCH] Config: Update auto-migration flow - Let the user know that migration is going to be attempted - Have a more informative error message if auto-migration fails - Revert back to the old config file on failure - Don't load with a partially parsed config Signed-off-by: kingbri --- common/tabby_config.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/common/tabby_config.py b/common/tabby_config.py index 13b8718..8b92f84 100644 --- a/common/tabby_config.py +++ b/common/tabby_config.py @@ -89,9 +89,7 @@ class TabbyConfig(TabbyConfigModel): if legacy: logger.warning( - "legacy config.yml files are deprecated, " - "please upadte to the new version.\n" - "Attempting auto migration" + "Legacy config.yml file detected. Attempting auto-migration." ) # Create a temporary base config model @@ -100,13 +98,27 @@ class TabbyConfig(TabbyConfigModel): try: config_path.rename(f"{config_path}.bak") generate_config_file(model=new_cfg, filename=config_path) + logger.info( + "Auto-migration successful. " + 'The old configuration is stored in "config.yml.bak".' + ) except Exception as e: - logger.error(f"Auto migration failed: {e}") + logger.error( + f"Auto-migration failed because of: {e}\n\n" + "Reverted all changes.\n" + "Either fix your config.yml and restart or\n" + "Delete your old YAML file and create a new " + 'config by copying "config_sample.yml" to "config.yml".' + ) # Restore the old config config_path.unlink(missing_ok=True) pathlib.Path(f"{config_path}.bak").rename(config_path) + # Don't use the partially loaded config + logger.warning("Starting with no config loaded.") + return {} + return unwrap(cfg, {}) def _from_args(self, args: dict):