标签异常

引发异常时,可以添加一个标签,它将替换你想用什么替换。

示例 yaml_snippet

a: 1
b:
  - 1
  - 2
from strictyaml import Map, Int, load, YAMLValidationError

标签 myfilename

load(yaml_snippet, Map({"a": Int(), "b": Map({"x": Int(), "y": Int()})}), label="myfilename")
strictyaml.exceptions.YAMLValidationError:
when expecting a mapping
  in "myfilename", line 2, column 1:
    b:
    ^ (line: 2)
found a sequence
  in "myfilename", line 4, column 1:
    - '2'
    ^ (line: 4)

可执行规范

handle-exceptions.story storytests 自动生成的文档。