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 <bdashore3@proton.me>
This commit is contained in:
kingbri 2024-09-16 18:15:50 -04:00
parent ebe7f3567e
commit d2d07ed92d

View file

@ -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):