Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gracefully exit when config file was not found #218

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions sodalite/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def run(path: Optional[str], update_access: Optional[str]) -> None:
except KeyboardInterrupt:
logger.debug('Received SIGINT - shutting down')
exit(1)
except ConfigNotFound:
click.echo("Config file not found", file=sys.stderr)
except ConfigNotFound as e:
click.echo(e.msg, file=sys.stderr)
exit(1)


Expand Down
11 changes: 9 additions & 2 deletions sodalite/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@


class ConfigNotFound(Exception):
pass
def __init__(self, path: Optional[Path] = None):
self.msg = "Couldn't find config file"
if path:
self.msg += f": {path}"
super().__init__(self.msg)


_ENV_CONFIG_FILE = 'CONFIG_FILE'
Expand All @@ -40,7 +44,10 @@ def _config_file() -> Path:
return config_file
else:
logger.info(f"Creating config file '{config_file}'")
shutil.copy(src=CONFIG_TEMPLATE, dst=config_file)
try:
shutil.copy(src=CONFIG_TEMPLATE, dst=config_file)
except FileNotFoundError:
raise ConfigNotFound(CONFIG_TEMPLATE)
return config_file

raise ConfigNotFound()
Expand Down