[mod] refactor error handling mecanism
This commit is contained in:
parent
7a1bdb033d
commit
2392e52dbd
17
prosopopoee
17
prosopopoee
@ -5,15 +5,22 @@ import sys
|
||||
import yaml
|
||||
|
||||
|
||||
def main():
|
||||
if not os.path.exists(os.path.join(os.getcwd(), "settings.yaml")):
|
||||
sys.stderr.write("I can't find a settings.yaml in the current working directory, abort\n")
|
||||
|
||||
def error(test, error_message):
|
||||
if not test:
|
||||
sys.stderr.write(error_message)
|
||||
sys.stderr.write("\n")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a settings.yaml in the current working directory, abort")
|
||||
|
||||
settings = yaml.safe_load("settings.yaml")
|
||||
|
||||
assert isinstance(settings, dict), "Your settings.yaml should be a dict"
|
||||
assert settings.get("title"), "You should specify a title in your main settings.yaml"
|
||||
error(isinstance(settings, dict), "Your settings.yaml should be a dict")
|
||||
error(settings.get("title"), "You should specify a title in your main settings.yaml")
|
||||
|
||||
title = settings["title"]
|
||||
sub_title = settings.get("sub_title", "")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user