-
-
Notifications
You must be signed in to change notification settings - Fork 602
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
panic: runtime error: index out of range [1] with length 1 #1341
Comments
Ah I see - there are two issues here.
To get what you want, you have to wrap watchlist into an array (if it's not one already) and then append to it: yq -p=xml -o=xml '.config.watchlist |= (select(tag == "!!seq") // [.]) + [{"x": "y"}]' file.xml The key bit is: |
Thank you for you help. The only drawback of your command is that when "watchlist" is not present, it add a I managed to fix this by using: yq -p=xml -o=xml '.config.watchlist |= (select(tag == "!!seq") // [ select(length > 0) ]) + [{"x": "y"}]' file.xml Thank you for your work on yq, it is a great tool to programmatically edit yaml, json and xml files :) |
Pleasure :) yq -p=xml -o=xml 'select(has(.config.watchlist)) | .config.watchlist |= (select(tag == "!!seq") // [.]) + [{"x": "y"}]' file.xml |
Fixed in 4.28.2 |
When trying to add a additionnal tag to a xml file, yq crash with the error
panic: runtime error: index out of range [1] with length 1
.Version of yq: 4.27.5
Operating system: Ubuntu 22.04 Impish Indri
Installed via: binary ( yq_linux_amd64.tar.gz )
Input document
File:
/etc/iwatch/iwatch.xml
Command
Actual behavior
Expected behavior
Additional context
When there is two
watchlist
tags in the input document, the command works without issue.The text was updated successfully, but these errors were encountered: