Create console error reports for YAML (and JSON) documents
Project description
yaml-error-report
Generate rich console errors reports for YAML (and JSON, since its a YAML subset) documents. This is aimed at console tools which want to present the user with useful errors messages if a YAML or JSON document fails some internal validation.
Uses PyYaml to extract location (line, column, position in stream) information for nodes in a YAML or JSON document. This information can then be used to create user friendly error reports.
Can be combined with jsonschema, to greatly improve error messages. See examples\with_jsonschema.
Installation
pip install yaml-error-report
Usage
# calc.yml
name: calc
methods:
- name: sum
description: "Sums x and y"
request:
- name: "x"
type: Int36
- name: "y"
type: Int32
response: Int32
# windows only: needed to make coloured output work
import colorama
colorama.init()
from yaml_error_report import path_to_location, error_report
# extract the text location of the offending node
loc = path_to_location("calc.yml", ["methods", 0, "request", 0, "type"])
# create the error report
error = error_report("YAML Validation Error", "Int36 is not a valid type", loc)
print(error)
outputs (nicely coloured on terminals)
YAML Validation Error
--> calc.yml:8:14
7| - name: "x"
8| type: Int36
^^^^^ Int36 is not a valid type
9| - name: "y"
10| type: Int32
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file yaml_error_report-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: yaml_error_report-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e99b94910e212dc926dbd0f357275b3f9966ca43a278de078cea6abc7580c81 |
|
MD5 | 2f0580de625c7b933b55c197e3f5b821 |
|
BLAKE2b-256 | 3ced144821e1420b084fb3a07219a9185d3fc577c1acf5da74001db10c885d67 |