From 3c733816420841adf630ee84544929832fd2034d Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Mon, 21 Nov 2022 15:58:47 +0100 Subject: [PATCH] error handling --- src/assets/config.schema.yaml | 2 +- src/cmd_optimise.py | 1 - src/main.py | 8 +++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/assets/config.schema.yaml b/src/assets/config.schema.yaml index db6401b..1470e45 100644 --- a/src/assets/config.schema.yaml +++ b/src/assets/config.schema.yaml @@ -25,10 +25,10 @@ $defs: $ref: "#/$defs/font-variation" css: - # https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#descriptors type: object additionalProperties: false patternProperties: + # https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face#descriptors ? "^ascent-override|descent-override|font-display|font-family|font-stretch|font-style|font-weight|font-feature-settings|font-variation-settings|line-gap-override|size-adjust|src|unicode-range$" : type: string diff --git a/src/cmd_optimise.py b/src/cmd_optimise.py index 439134f..aa8ed97 100644 --- a/src/cmd_optimise.py +++ b/src/cmd_optimise.py @@ -1,4 +1,3 @@ -import copy import hashlib import json import os diff --git a/src/main.py b/src/main.py index df3d99a..79c5c67 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,6 @@ import click +import jsonschema import cmd_optimise import flags @@ -24,7 +25,12 @@ def cli(verbose, config, output_directory, clean, prefix): # Run c = load(config) - validate(c) + try: + validate(c) + except jsonschema.exceptions.ValidationError as e: + click.echo(f"Config validation failed:") + click.echo(f"{e.message} @ {e.json_path}") + exit(1) cmd_optimise.optimise(c)