Skip to content

Commit

Permalink
Config: Update auto-migration flow
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
kingbri1 committed Sep 16, 2024
1 parent ebe7f35 commit d2d07ed
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions common/tabby_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def _from_file(self, config_path: pathlib.Path):

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
Expand All @@ -100,13 +98,27 @@ def _from_file(self, config_path: pathlib.Path):
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):
Expand Down

0 comments on commit d2d07ed

Please sign in to comment.