# Programmatic way to find the bad spot in a YAML file?

**URL:** <https://www.ruby-forum.com/t/programmatic-way-to-find-the-bad-spot-in-a-yaml-file/112078>\
**Category:** Rails\
**Created:** [August 15, 2007, 12:54am UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-the-bad-spot-in-a-yaml-file/112078 "2007-08-15T00:54:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [August 15, 2007, 12:54am UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-the-bad-spot-in-a-yaml-file/112078/1 "2007-08-15T00:54:19Z")

</div>

I have a very large YAML file (approx 5000 entries) that I am loading.  
Somewhere along the way, it doesn’t like something in the file so I  
get a :

/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/  
lib/ruby/1.8/yaml.rb:133:in `utc': time out of range (ArgumentError) from /Applications/Locomotive2/Bundles/ standardRailsMar2007.locobundle/i386/lib/ruby/1.8/yaml.rb:133:in`node\_import’  
from /Applications/Locomotive2/Bundles/  
standardRailsMar2007.locobundle/i386/lib/ruby/1.8/yaml.rb:133:in  
`load' from /Applications/Locomotive2/Bundles/ standardRailsMar2007.locobundle/i386/lib/ruby/1.8/yaml.rb:133:in`load’

Which is all well and good but it doesn’t give me the offending line  
in the YAML file. Anyone write anything out there that helps pinpoint  
where in your YAML file things went south?

Thanks,

Scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [August 15, 2007, 5:07am UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-the-bad-spot-in-a-yaml-file/112078/2 "2007-08-15T05:07:32Z")

</div>

[CC’d to the YAML-core list]

Scott wrote:

> I have a very large YAML file (approx 5000 entries) that I am loading.  
> Somewhere along the way, it doesn’t like something in the file so I  
> get a :
> 
> /Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/  
> lib/ruby/1.8/yaml.rb:133:in `utc’: time out of range (ArgumentError)

> Which is all well and good but it doesn’t give me the offending line  
> in the YAML file. Anyone write anything out there that helps pinpoint  
> where in your YAML file things went south?

I asked this before and got nothing. Syck simply needs a new feature.  
YAML  
is not useful until its parsing becomes fault-tolerance and  
introspective.

Workaround: Can you cut your file up into 5000 files of 1 entry each?  
Seriously - to make one file out of them, I would host each segment in

> cough\< XML.

Also, you could try a JSON parser…

–  
Phlip  
[http://www.oreilly.com/catalog/9780596510657/](http://www.oreilly.com/catalog/9780596510657/)  
“Test Driven Ajax (on Rails)”  
assert\_xpath, assert\_javascript, & assert\_ajax

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [August 15, 2007, 5:54pm UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-the-bad-spot-in-a-yaml-file/112078/3 "2007-08-15T17:54:06Z")

</div>

There is another “C” version of YAML which is quite fast and gives very  
good exception reporting, at [http://pyyaml.org/wiki/LibYAML](http://pyyaml.org/wiki/LibYAML), perhaps it  
needs a ruby binding? For a pure ruby solution, see  
[http://rbyaml.rubyforge.org/](http://rbyaml.rubyforge.org/)  
it should also have better error reporting than syck.

On Tue, Aug 14, 2007 at 07:50:19PM -0700, Phlip wrote:  
| I asked this before and got nothing. Syck simply needs a new feature. YAML  
| is not useful until its parsing becomes fault-tolerance and introspective.

On Tue, Aug 14, 2007 at 08:34:38PM -0700, Phlip wrote:  
| The outer problem is fault tolerance. Our programs can only be as  
| user-friendly and fault-tolerant as their libraries. The lower the library,  
| the more tolerance. I can’t ask my customers to enter all their data in YAML  
| until I can highlight the line and column of their errors for them.
