error handling on config load

This commit is contained in:
cupcakearmy 2022-11-27 01:14:24 +01:00
parent 61d4f0e52e
commit a77f6f1c06
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F

View File

@ -1,5 +1,6 @@
import os
import click
import jsonschema
import yaml
@ -31,9 +32,17 @@ def validate(config):
def load(path):
# Load config
path = os.path.abspath(path)
with open(path, 'r') as f:
config = yaml.safe_load(f)
try:
path = os.path.abspath(path)
with open(path, 'r') as f:
config = yaml.safe_load(f)
except FileNotFoundError:
click.echo(f"Config file not found: {path}")
exit(1)
except yaml.YAMLError as e:
click.echo(f"Config file is not valid YAML: {path}")
click.echo(e)
exit(1)
# Setting dynamic defaults
default_config['context'] = os.path.dirname(path)