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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for yaml_error_report-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e99b94910e212dc926dbd0f357275b3f9966ca43a278de078cea6abc7580c81 |
|
MD5 | 2f0580de625c7b933b55c197e3f5b821 |
|
BLAKE2b-256 | 3ced144821e1420b084fb3a07219a9185d3fc577c1acf5da74001db10c885d67 |