-
Notifications
You must be signed in to change notification settings - Fork 89
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
[Enhancement] : Better error message with line number #117
Comments
Thanks for your interest in Yamale. I agree, the line number would be helpful. To be complete, we'd probably want to update the error class to hold the line numbers separately. It'll take a little thought. Thanks for the start towards that. For your code, be careful using Thanks! |
My pleasure ! Should I close this "issue" ? |
No, we'll leave it open as a reminder that people would like to have a line number in the output. |
Would very much appreciate this feature 👍 |
Would a PR along these lines be welcome? Our yamale fork now has "promoted" error messages, which hold a few separate properties (error message, ancestry list, pointer to data evaluated, etc). I need to look closer at the above, because having line numbers as another property would be useful for displaying to users. Anyhow, with a few changes and cleanup, I think it'd be PR-able--if it's not stepping on a WIP, @mildebrandt. |
@mechie That would be very welcome....it seems there is interest and we haven't been working towards this feature internally. |
Great proposal. We are interested in this feature as well! :-) |
Hi @mildebrandt and the other contributors.
First thank you for this amazing library.
I honestly think this should be the standard way to validate YAML schema.
It would be amazing if you can reach "ruamel.yaml" and "pyyaml" so they could include your library and set the way to validate schema in YAML.
Anyway. I started using Yamale and found myself to wish to get the line number in the yaml file where I have errors.
I am using ruamel.yaml, (I don't really now pyyaml but I guess it should be possible too).
I use ruamel.yaml in round-trip mode and extract the line number of each keys and I copy your format (with the '.' for nested keys). I get a one level dict with the line number.
Here below my code with comments as well as an example with output.
I hope you will find it a nice addition, ideally I see that you add the line numbers into
yamale.YamaleError.results.errors
Then in another file I use it like that :
I guess the code can be improved, I tested quiet a lot but I admit I did not try special cases. But it should not crash as I handled errors, maximum you don't get the line number (just a '?').
I tried to be careful to use only "public" method from ruamel.yaml (CommentedMap.lc.data[key][0]).
(I am on Python 3.8, ruamel.yaml 0.16.6 and yamale 3.0.1)
Here below an example:
schema.yaml:
data.yaml :
And this is the output I am getting:
The text was updated successfully, but these errors were encountered: