# YAML::Syck fault tolerance

**URL:** <https://www.ruby-forum.com/t/yaml-syck-fault-tolerance/82724>\
**Category:** Ruby\
**Created:** [January 20, 2007, 12:10am UTC](https://www.ruby-forum.com/t/yaml-syck-fault-tolerance/82724 "2007-01-20T00:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [January 20, 2007, 12:10am UTC](https://www.ruby-forum.com/t/yaml-syck-fault-tolerance/82724/1 "2007-01-20T00:10:22Z")

</div>

Ruboids:

I need to read a block of YAML and recover gracefully if it fails. The  
current loader apparently throws away all the representation it loaded  
at  
error time.

Is there some way to get the representation loaded before the error  
happens?

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [January 21, 2007, 12:38pm UTC](https://www.ruby-forum.com/t/yaml-syck-fault-tolerance/82724/2 "2007-01-21T12:38:50Z")

</div>

On 1/20/07, Phlip [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ruboids:
> 
> I need to read a block of YAML and recover gracefully if it fails. The  
> current loader apparently throws away all the representation it loaded at  
> error time.
> 
> Is there some way to get the representation loaded before the error  
> happens?

Not tested idea: If the exception contains error position, try cutting  
the string just before the error and retry… (althoug this won’t be a  
stable solution, it’s more a hack)

---

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [January 21, 2007, 5:46pm UTC](https://www.ruby-forum.com/t/yaml-syck-fault-tolerance/82724/3 "2007-01-21T17:46:20Z")

</div>

Jan S. wrote:

> Not tested idea: If the exception contains error position, try cutting  
> the string just before the error and retry… (althoug this won’t be a  
> stable solution, it’s more a hack)

That’s what I hacked-in shortly after posting. The actual bug was  
something  
truncated a database BLOB containing the YAML. The hack works for  
stereotypical YAML with one line per record…

Architecturally, and only for curiosity, I have heard there’s an XML  
system  
called SAX that calls a callback for each node it reads. If a YAML  
system  
could do that, I could collect the nodes up to the break point, then I  
wouldn’t need to worry about the hack…
