# Yaml load error (when using cgi)

**URL:** <https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822>\
**Category:** Ruby\
**Created:** [May 6, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822 "2008-05-06T17:45:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [May 6, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822/1 "2008-05-06T17:45:55Z")

</div>

i’ve a cgi wanted to make use of yaml and i get this error reported by  
Apache2 :

[Tue May 06 12:25:50 2008] [error] mod\_ruby: error in ruby  
[Tue May 06 12:25:50 2008] [error] mod\_ruby:  
/opt/local/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 3, col -1:` manpath: “” (ArgumentError)  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: search: man  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: section: “”  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: : 1  
[Tue May 06 12:25:50 2008] [error] mod\_ruby:  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: yaml:  
/Users/yt/Sites/man/man\_rep/history.yaml  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: ’  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: from  
/opt/local/lib/ruby/1.8/yaml.rb:133:in `load' [Tue May 06 12:25:50 2008] [error] mod_ruby: from /Users/yt/Sites/man/index.rbx:30 [Tue May 06 12:25:50 2008] [error] mod_ruby: from /opt/local/lib/ruby/1.8/apache/ruby-run.rb:53:in`load’  
[Tue May 06 12:25:50 2008] [error] mod\_ruby: from  
/opt/local/lib/ruby/1.8/apache/ruby-run.rb:53:in `handler’

the calling line being :  
history=YAML::load( File.open( YAMLFILE ) )

and the yaml file being no more than :  
— history.yaml ------------------------------  
— !ruby/object:History  
items:  
!ruby/object:Item ?  
manpath: “”  
search: man  
section: “”  
: 1

yaml: /Users/yt/Sites/man/man\_rep/history.yaml  
— history.yaml ------------------------------

I should mention i don’t have prob when testing that apart from Apache2  
and cgi.

When testing under Apache2/cgi my requirements are :  
require ‘rubygems’  
require ‘cgi’  
require ‘fileutils’  
require ‘yaml’  
require ‘history’

When testing standalone:  
require ‘rubygems’  
require ‘yaml’  
require ‘history’

the ‘history’ script being a class History of mine, nothing to do (i  
believe) with the prob.

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [May 10, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822/2 "2008-05-10T19:45:38Z")

</div>

removed\_email\_address@domain.invalid (Une BÃ©vue) writes:

> /opt/local/lib/ruby/1.8/yaml.rb:133:in `load': syntax error on line 3, col -1:` manpath: “” (ArgumentError)

Can you load the yaml file from outside your CGI script? Are both the  
History and Item class loaded into the runtime before you load the  
yaml file?

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [May 10, 2008, 8:45pm UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822/3 "2008-05-10T20:45:33Z")

</div>

Peter J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can you load the yaml file from outside your CGI script?

Nope…

> Are both the  
> History and Item class loaded into the runtime before you load the  
> yaml file?

YES, because of “rubygems”

i’ve tried :  
require ‘man\_rep/manpage’  
require ‘rubygems’  
require ‘cgi’  
require ‘yaml’

=\> that way probs with yaml

require ‘rubygems’  
require ‘yaml’  
require ‘cgi’  
require ‘man\_rep/manpage’

=\> that way probs with rubygems (unable to find man\_rep/manpage …)

but i could try something else, using “computed” absolute path for  
‘man\_rep/manpage’

thanks for your answer !

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [May 10, 2008, 9:22pm UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822/4 "2008-05-10T21:22:33Z")

</div>

removed\_email\_address@domain.invalid (Une BÃ©vue) writes:

> > Can you load the yaml file from outside your CGI script?
> 
> Nope…

I think the core issue is that your YAML file is malformed. How did  
you create it?

Load it in IRB and track down the syntax error in the YAML file:

,----  
| \>\> # load all your libs  
| \>\> h = YAML.load\_file(‘filename’)  
`----

---

<div class="post-metadata">

**Author:** ![Une\_BSSSSvS\_ue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/2acd7d/32.png) [@Une\_BSSSSvS\_ue](https://www.ruby-forum.com/u/Une_BSSSSvS_ue)\
**Post date:** [May 11, 2008, 9:45am UTC](https://www.ruby-forum.com/t/yaml-load-error-when-using-cgi/136822/5 "2008-05-11T09:45:34Z")

</div>

Peter J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I think the core issue is that your YAML file is malformed. How did  
> you create it?

to read it :  
history\_file=“man\_rep/history.yaml”  
history=YAML::load( File.open(history\_file))

to write it:  
File.open( history\_file, “w” ) {|f| f.write( history.to\_yaml ) }

history being an Array of Page(s), Page is a simple class of mine.

> Load it in IRB and track down the syntax error in the YAML file:

I’ll look at however, i don’t think it’s corrupted because, i’ve trashed  
it regularly…

thanks for the tip !
