-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confusing YAMLValidationError when comments are present in YAML string #164
Comments
Thanks Giacomo,
Ill take a look tonight.
…On Wed, 26 Jan 2022, 13:23 Giacomo Benelli, ***@***.***> wrote:
Hi, thanks for strictYAML. Looking to replace my Schema-based validation
with it.
One of the reason for me to switch is the better error messages that allow
my users to fix their YAMLs more quickly.
I've noticed something about the YAMLValidationError strings. When
comments are present in the YAML between a key: and its value, if there
is a validation error, then the presence of the comment line seems to
generate confusing error messages.
This is what I mean: the following yaml is parsed correctly and the
comment is ignored and discarded (OK)
yaml_string = """key: # comment - 1"""
generic_config = load(
yaml_string,
Map({'key': Seq(Int())}),
)
If I now force a validation error, i.e. providing a string not convertible
to a number
yaml_string = """key: # comment - value"""
generic_config = load(
yaml_string,
Map({'key': Seq(Int())}),
)
then I get a validation error which seems to refer to the right thing (expecting
an integer) but to the wrong line (the one where the comment is present)
strictyaml.exceptions.YAMLValidationError: when expecting an integer
found arbitrary text
in "<unicode string>", line 2, column 1:
# comment
^ (line: 2)
Other variant: if I postpone the comment line in the YAML string, then the
error seems to be double:
yaml_string = """key: - value # comment"""
generic_config = load(
yaml_string,
Map({'key': Seq(Int())}),
)
generates the following:
strictyaml.exceptions.YAMLValidationError: when expecting an integer
in "<unicode string>", line 2, column 1:
- value
^ (line: 2)
found arbitrary text
in "<unicode string>", line 3, column 1:
# comment
^ (line: 3)
I'd expect comments to just not influence the error messages. Am I right?
Thanks for any time you could dedicate to this.
—
Reply to this email directly, view it on GitHub
<#164>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOJKNMOLJTZGZB5WLBUFPLUX7YTNANCNFSM5M3AYUKA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I see the same behavior using latest (1.7.3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for strictYAML. Looking to replace my Schema-based validation with it.
One of the reason for me to switch is the better error messages that allow my users to fix their YAMLs more quickly.
I've noticed something about the YAMLValidationError strings. When comments are present in the YAML between a
key:
and itsvalue
, if there is a validation error, then the presence of the comment line seems to generate confusing error messages.This is what I mean: the following yaml is parsed correctly and the comment is ignored and discarded (OK)
If I now force a validation error, i.e. providing a string not convertible to a number
then I get a validation error which seems to refer to the right thing (
expecting an integer
) but to the wrong line (the one where the comment is present)Other variant: if I postpone the comment line in the YAML string, then the error seems to be double:
generates the following:
I'd expect comments to just not influence the error messages. Am I right?
Thanks for any time you could dedicate to this.
The text was updated successfully, but these errors were encountered: