Labeling exceptions

When raising exceptions, you can add a label that will replace with whatever you want.

Example yaml_snippet:

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

Label 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)

Executable specification

Page automatically generated from handle-exceptions.story.