Exit the system instead of raising Exception

pull/1805/head
Sandra Serrano 2 years ago committed by GitHub
parent 3ed2750794
commit 62c70402c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -112,16 +112,14 @@ def check_toml(template_file, config_file) -> dict:
template = toml.load(template_file) template = toml.load(template_file)
except Exception as error: except Exception as error:
console.print(f"[red bold]Encountered error when trying to to load {template_file}: {error}") console.print(f"[red bold]Encountered error when trying to to load {template_file}: {error}")
raise sys.exit()
try: try:
config = toml.load(config_file) config = toml.load(config_file)
except toml.TomlDecodeError: except toml.TomlDecodeError:
console.print( console.print(f"""[blue]Couldn't read {config_file}. Overwrite it?(y/n)""")
f"""[blue]Couldn't read {config_file}. Overwrite it?(y/n)"""
)
if not input().startswith("y"): if not input().startswith("y"):
print("Unable to read config, and not allowed to overwrite it. Giving up.") print("Unable to read config, and not allowed to overwrite it. Giving up.")
raise sys.exit()
else: else:
try: try:
with open(config_file, "w") as f: with open(config_file, "w") as f:
@ -131,11 +129,9 @@ def check_toml(template_file, config_file) -> dict:
f"[red bold]Failed to overwrite {config_file}. Giving up." f"[red bold]Failed to overwrite {config_file}. Giving up."
f"\nSuggestion: check {config_file} permissions for the user." f"\nSuggestion: check {config_file} permissions for the user."
) )
raise sys.exit()
except FileNotFoundError: except FileNotFoundError:
console.print( console.print(f"""[blue]Couldn't find {config_file} Creating it now.""")
f"""[blue]Couldn't find {config_file} Creating it now."""
)
try: try:
with open(config_file, "x") as f: with open(config_file, "x") as f:
f.write("") f.write("")
@ -145,7 +141,7 @@ def check_toml(template_file, config_file) -> dict:
f"[red bold]Failed to write to {config_file}. Giving up." f"[red bold]Failed to write to {config_file}. Giving up."
f"\nSuggestion: check the folder's permissions for the user." f"\nSuggestion: check the folder's permissions for the user."
) )
raise sys.exit()
console.print( console.print(
"""\ """\

Loading…
Cancel
Save