From fab1eaa4f890828ea73490b601bcf93cbd8a207b Mon Sep 17 00:00:00 2001 From: Pedro Baptista Date: Tue, 5 Dec 2023 23:34:06 +0000 Subject: [PATCH] Beautify error output Print a concise message pointing to the violation location along with the cause Issue: 24 --- zuulcilint/__main__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/zuulcilint/__main__.py b/zuulcilint/__main__.py index 3c263f0..b8cac77 100644 --- a/zuulcilint/__main__.py +++ b/zuulcilint/__main__.py @@ -43,14 +43,19 @@ def lint(file_path: str, schema: dict) -> int: obj = yaml.safe_load(yaml_in) va_errors = validator.iter_errors(obj) for e in va_errors: - print(e, file=sys.stderr) + zuul_utils.print_bold("Validation error:", "error") + print(f" File: {file_path}") + print(f" Message: {e.message}") + print(f" Path: {list(e.path)}") + print(f" Schema Path: {list(e.schema_path)}\n") errors += 1 except yaml.YAMLError as e: - print(e) + print(f"YAML Parse Error: {e}") errors += 1 except FileNotFoundError as e: print(f"{e.filename} not found!\nExiting") sys.exit(1) + return errors