It is hard to debug big YAML files because parsed objects do not have their position info; we have to search where are wrong values in the original YAML by eye.
I'm developing a Gem named YPS: YAML Positioning System.
https://github.com/taichi-ishitani/yps
YPS is a Gem to parse YAML and add position info to parsed objects. Parsed objects have the accessor named #position
that returns their position info.
You can use this method to get position info in the original YAML of the receiver object.
Here is an example.
require 'yps'
yaml = YPS.load(<<~'YAML')
children:
- name: kanta
age: 8
- name: kaede
age: 3
YAML
# output
# name: kanta (filename: unknown line 2 column 11)
# age: 8 (filename: unknown line 3 column 10)
# name: kaede (filename: unknown line 4 column 11)
# age: 3 (filename: unknown line 5 column 10)
yaml['children'].each do |child|
child.each do |key, value|
puts "#{key}: #{value} (#{value.position})"
end
end
For more details, please visit its repository and API doc.
Top comments (0)