为YAML(和JSON)文档创建控制台错误报告
yaml-error-report的Python项目详细描述
yaml错误报告
为YAML(和JSON,因为它是YAML的子集)文档生成丰富的控制台错误报告。 这是针对那些希望在YAML或JSON文档未能通过一些内部验证时向用户显示有用的错误消息的控制台工具。在
使用PyYaml为YAML或JSON文档中的节点提取位置(行、列、流中的位置)信息。 然后可以使用此信息创建用户友好的错误报告。在
可以与jsonschema结合使用,以大大改善错误消息。 见examples\with_jsonschema。在
安装
pip install yaml-error-report
使用
^{pr2}$# windows only: needed to make coloured output workimportcoloramacolorama.init()fromyaml_error_reportimportpath_to_location,error_report# extract the text location of the offending nodeloc=path_to_location("calc.yml",["methods",0,"request",0,"type"])# create the error reporterror=error_report("YAML Validation Error","Int36 is not a valid type",loc)print(error)
outputs(终端上的颜色很好)
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
- 项目
标签: