mirror of
https://github.com/cupcakearmy/glyphance.git
synced 2024-12-22 08:06:29 +00:00
error handling on config load
This commit is contained in:
parent
61d4f0e52e
commit
a77f6f1c06
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
import click
|
||||||
import jsonschema
|
import jsonschema
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -31,9 +32,17 @@ def validate(config):
|
|||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
# Load config
|
# Load config
|
||||||
|
try:
|
||||||
path = os.path.abspath(path)
|
path = os.path.abspath(path)
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
config = yaml.safe_load(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
|
# Setting dynamic defaults
|
||||||
default_config['context'] = os.path.dirname(path)
|
default_config['context'] = os.path.dirname(path)
|
||||||
|
Loading…
Reference in New Issue
Block a user