-
Notifications
You must be signed in to change notification settings - Fork 280
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
Showing the line range that caused the error #681
Comments
Hello ! I'm not sure I understand well what you mean. You don't care about the failed lines and columns, but you care about the subpart of the YAML code that caused the failure. Is that it? |
Close, because the resulting YAML file is generated from templates the line range alone makes it difficult to discern what actually triggered the error 😄 Showing the line range and maybe 1/2 extra lines for padding/context would be very useful. If you're not a domain expert, a quick skim of the docs should assist in explaining why this would be hard to debug. |
Exactly that yes! I don't think it needs to be too fancy, just show the line range (maybe behind an option in case people want the current behaviour instead) and 1/2 extra either side for context. |
I'm doing similar with simple sed. if ! result=$(echo "$yaml" | yamllint --format "parsable" -); then
# error message
echo "$result"
line=$(echo "$result" | cut -d':' -f2)
context_lines=3 # line numer to show before&after (e.g. 1 line)
# Adjust not to exceed under 1st line
start_line=$((line - context_lines))
if [ "$start_line" -lt 1 ]; then
start_line=1
fi
# Adjust not to exceed over final line
total_lines=$(echo "$manifest" | wc -l)
end_line=$((line + context_lines))
if [ "$end_line" -gt "$total_lines" ]; then
end_line=$total_lines
fi
# show line
echo "$manifest" | cat -n - | sed -n "${start_line},${end_line}p"
exit 1
fi |
Thanks for yamllint, this is a great tool!
The usecase we have for it is ensuring that our Helm templates don't include things like duplicate keys and such that
helm lint
doesn't pick up by default; and as such we pipe the result of the command that generates the output into yamllint.Because there's no file that we can look at, having the failed line numbers isn't quite that useful as it's built from multiple templates.
Would be really good if this could be added 😄 Thanks!
The text was updated successfully, but these errors were encountered: